# Help with default datetime field

**URL:** <https://discuss.tryton.org/t/help-with-default-datetime-field/8322>\
**Category:** Developer\
**Created:** [February 18, 2025, 3:25pm UTC](https://discuss.tryton.org/t/help-with-default-datetime-field/8322 "2025-02-18T15:25:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxx](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/maxx/32/2320_2.png) [@maxx](https://discuss.tryton.org/u/maxx)\
**Post date:** [February 18, 2025, 3:25pm UTC](https://discuss.tryton.org/t/help-with-default-datetime-field/8322/1 "2025-02-18T15:25:07Z")

</div>

Hi,

In a custom model, i’m using a datetime field for calendar event.  
How to set a default planned date to have today as date and ‘00:00:00’ as time ?

I try such code:

```auto
@classmethod                                                                                     
def default_planned_date(cls):                                                                                                                  
    return dt.datetime.now().replace(hour=0, minute=0, second=0,                                 
        microsecond=0)

```

But I have ‘01:00:00’ instead of ‘00:00:00’ as time

 ![image](https://discuss-cdn.tryton.org/uploads/default/original/2X/d/d8a25cfe1902a82ed0a619a66b8065a899ef1405.png)

When returning datetime.now()

```auto
@classmethod                                                                                     
def default_planned_date(cls):                                                                                                                  
    return dt.datetime.now()

```

Then time is correct…

 ![image](https://discuss-cdn.tryton.org/uploads/default/original/2X/b/b26d6c6afd48d8264f0bcbebd1af90b24f8875ab.png)

Any idea ?

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [February 18, 2025, 3:29pm UTC](https://discuss.tryton.org/t/help-with-default-datetime-field/8322/2 "2025-02-18T15:29:04Z")

</div>

This is because on server side, the datetime are always in UTC but on the client side the datetime is rendered in the timezone of the OS.

So I do not know what you want to represent but you should consider:

- is it really a fixed point in time, so you must use a datetime but set time part to 0 has no real meaning
- is it a conventional time of a date, so it is probably a date and a time fields.

---

<div class="post-metadata">

**Author:** ![maxx](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/maxx/32/2320_2.png) [@maxx](https://discuss.tryton.org/u/maxx)\
**Post date:** [February 18, 2025, 3:41pm UTC](https://discuss.tryton.org/t/help-with-default-datetime-field/8322/3 "2025-02-18T15:41:05Z")

</div>

Thanks for the explanation.

We have 2 types of shipment events:

- We don’t know what time it should be delivered/shipped, so we don’t care about time to have an “all day event” (ics calendar event with only a dtstart without time)
- The carrier warns us about the delivery/shipping time so we need the time to have the event at the correct time in the calendar (there’s a function field that define an “end” with a 1 hour interval from specified time) (ics calendar event with dtstart and dtend)

Probably, I should have two distinct fields : date and time. Time field will be invisible in case of an “All day event” (boolean field)

---

<div class="post-metadata">

**Author:** ![maxx](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/maxx/32/2320_2.png) [@maxx](https://discuss.tryton.org/u/maxx)\
**Post date:** [February 18, 2025, 3:43pm UTC](https://discuss.tryton.org/t/help-with-default-datetime-field/8322/4 "2025-02-18T15:43:55Z")

</div>

Anyway, why is the time “now” with the correct timezone and the “forced” time to midnight with 1 hour more ?

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [February 18, 2025, 3:45pm UTC](https://discuss.tryton.org/t/help-with-default-datetime-field/8322/5 "2025-02-18T15:45:26Z")

</div>

Because now is now in every timezones.

---

<div class="post-metadata">

**Author:** ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)\
**Post date:** [February 19, 2025, 3:45pm UTC](https://discuss.tryton.org/t/help-with-default-datetime-field/8322/6 "2025-02-19T15:45:26Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
