RyanJ Posted February 9, 2016 Share Posted February 9, 2016 It's been too long. Finally got to get back to PW after wading in some MODX development for a while. Anyhow, I am a bit stumped on something. I have incorporated a date field and for some reason it converts back to 12/31/1969 after saving the page. When I add a date picker to the field, it does not even offer the current year. It offers a few years from the 70's which I hear were good years, but wont help me here. I have tried multiple configurations in the settings but ultimately end up with the same value. echoing out the date("m/d/Y") prints the correct date time zone is set in both my config file and php.ini php.ini - date.timezone = America/New_York config - $config->timezone = 'America/New_York'; pw version - 2.7.2 Thanks for any suggestions and its good to be back working with pw. Link to comment Share on other sites More sharing options...
cstevensjr Posted February 9, 2016 Share Posted February 9, 2016 Are you sure this date is not coming from MySQL? Link to comment Share on other sites More sharing options...
RyanJ Posted February 9, 2016 Author Share Posted February 9, 2016 Possibly? I don't see a timezone set in the MySQL config file. Does that need to be set? Link to comment Share on other sites More sharing options...
cstevensjr Posted February 9, 2016 Share Posted February 9, 2016 Thinking about it a little more, maybe the config setting is for MySQL. Need to investigate a little more. Link to comment Share on other sites More sharing options...
cstevensjr Posted February 9, 2016 Share Posted February 9, 2016 Ok, the config setting is using the PHP date format. http://cheatsheet.processwire.com/system-configuration/date-and-time/config-timezone/ https://processwire.com/api/variables/config/ What versions of PHP and MySQL are you using? Link to comment Share on other sites More sharing options...
GuruMeditation Posted February 9, 2016 Share Posted February 9, 2016 Not sure if this is relevant, but in your config file, do you have the dateFormat set? i.e $config->dateFormat = 'Y-m-d H:i:s'; Also, I had some weird behaviour with dates once, so I deleted the field and recreated it and it worked normally after that. Link to comment Share on other sites More sharing options...
RyanJ Posted February 9, 2016 Author Share Posted February 9, 2016 I figured out the issue. User error and some default behavior in the mix. When an invalid date format is entered for example "2012", the date reverts back to 1969-12-31 after page save. I guess that is the default date input format, because if I select none, it reverts back to that. Can someone confirm this is normal behavior. Thanks for all the suggestions and assistance so far. 1 Link to comment Share on other sites More sharing options...
DaveP Posted February 10, 2016 Share Posted February 10, 2016 1 Jan 1970 is the start of the Unix epoch. As you are no doubt aware, date/times are stored in the db as seconds after that point. Haven't looked into it too deeply, but I should imagine that refers to UTC (broadly equivalent to GMT), so at 0 seconds UTC your time zone will be sometime on 31 Dec 1969. tldr; the db is returning 0. 2 Link to comment Share on other sites More sharing options...
RyanJ Posted February 10, 2016 Author Share Posted February 10, 2016 That does make sense Dave, thanks. However maybe I am misunderstanding how this fields settings works. Under the input tab on this fields settings, If I modify the "Date Input Format" to none and then modify the "Date Input Format Code" to "Y" per PHP Date then an acceptable format for this field should be the full year ie "2012". Is this not correct? When doing so the value reverts back to 1969 and the value stored in the DB is 1969-12-31 19:33:32 Link to comment Share on other sites More sharing options...
DaveP Posted February 10, 2016 Share Posted February 10, 2016 AFAIK the field should act like PHP's strtotime() function (as inputs are run through that function), so if that function translates a year number to a valid date, then something else is going on. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now