Jump to content

Date time field unset if empty?


benbyf
 Share

Recommended Posts

Is there any built in way of disregarding the time on output in a datetime field is the time was orginially set?

Ive gone from using the date only to using both date and time, but any timeless pages default to outputing 12:00am which looks odd having many pages listed in this way.

Any thoughts would be welcome

Link to comment
Share on other sites

Datetime fields are stored in the DB as timestamps - this is true regardless of whether you have a timepicker on the inputfield or not.

So you can output the value of a datetime field in any format you like. Get the timestamp with getUnformatted() and then format it with date(). You could check the time to see if it's 12:00am and if so format the timestamp without a time component. But I don't think you can use code to distinguish between situations where no time was entered and 12:00am was deliberately entered.

Link to comment
Share on other sites

9 hours ago, Robin S said:

Datetime fields are stored in the DB as timestamps - this is true regardless of whether you have a timepicker on the inputfield or not....

Not quite. Datetime fields are actually stored as MySQL datetime fields in the db. For the wakeupValue this always gets converted from 'Y-m-d H:i:s' string to timestamp via strtotime. Once you save the field the timestamp is converted to 'Y-m-d H:i:s' and stored in the db.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...