Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

max. future date of SS_datetime??


Go to End


5 Posts   2381 Views

Avatar
fj

Community Member, 7 Posts

8 March 2011 at 3:46am

what is the maximum future date of an SS_Datetime field in a model??
I try to set "9999-31-12 23:59:00" and "2099-31-12 23:59:00" via YAML fixture file but both values do not work.
"2029-12-11 23:59:00" works fine. hmmm.
thanks!

Avatar
Devlin

Community Member, 344 Posts

10 March 2011 at 6:16am

I try to set "9999-31-12 23:59:00" and "2099-31-12 23:59:00"
There is no 31st month.

The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
http://dev.mysql.com/doc/refman/5.1/en/datetime.html

Avatar
fj

Community Member, 7 Posts

10 March 2011 at 8:45pm

Sorry, wrote it down the wrong way.

now, I try to set "2039-12-31 23:59:00" but that does not work. I guess it's some 32bit unix timestamp issue. Could the default SS date parser be an issue here?

Avatar
Devlin

Community Member, 344 Posts

10 March 2011 at 9:51pm

I have no problem to save or parse that kind of date. Did you check your database and tried to insert the date via phpMyAdmin? May be it's a formatting issue with DateField.

Avatar
fj

Community Member, 7 Posts

10 March 2011 at 11:15pm

Edited: 10/03/2011 11:18pm

OK, got it fixed. here is how:

# when setting the date value to an SS_Datetime field by string (like "2039-12-31 23:59:00") the setValue method of SS_Datetime converts this string into a unix timestamp using strtotime. That timestamp is used to create a formatted string ('Y-m-d H:i:s') representing the date. but the timestamp seems to have some limitation (see http://www.tareeinternet.com/forum/knowledgebase/53-detailed-timestamp-information-tutorial.html)

# so I extended the SS_Datetime class and overwrote the setValue() method. This allows me to use the php DateTime class (since php 5.2) to create the formatted string ('Y-m-d H:i:s') and set the objects value directly.

# now I use the extended "eXSS_Datetime" classes in my models