Jump to content
RyanJ

Date fieldtype reverts to 12/31/1969

Recommended Posts

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.

Share this post


Link to post
Share on other sites

Possibly? I don't see a timezone set in the MySQL config file. Does that need to be set?

Share this post


Link to post
Share on other sites

Thinking about it a little more, maybe the config setting is for MySQL.  Need to investigate a little more.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

  • Like 1

Share this post


Link to post
Share on other sites

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.

  • Like 2

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Sanyaissues
      Hi all,
      I have some pages with a custom datefield who stores the birth of the person. I want to show a list with the birthdays of the current month but i don't now how to get all the pages that match the condition.
      I know that this doesn't work but it reflex what i'm trying to achieve:
      $today = getdate(); $currentmonth = $today[month]; //november $people = $pages->get("/people/")->find("birthday~=$currentmonth"); //voila i get all the people who born on november! birthday is an custom datefield...
      Anybody could spare me a tip? Thanks!
    • By onjegolders
      Not sure whether this is a known bug or something else is causing the problem.
      Basically my custom date field is being wiped when I resave the page.
      So on first adding the date and saving all is well, or if the date is added last thing before clicking save then no problems but otherwise the datefield just empties.
      I am also using the datepicker (not sure if this has any bearing on it)
×
×
  • Create New...