Skip Navigation

[Résolu] Date Field bug: on save, get error "Please enter a date after 1 January 1970"

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
Create a custom date field, No matter what date I choose from the datepicker (custom date field in a custom post type), when I save the content it always says "Please enter a date after 1 January 1970".
Solution:
the problem is in the Types file \types\library\toolset\types\embedded\functions.php, line 737~745:

/**
 * Checks if timestamp supports negative values.
 *
 * @return type
 */
function fields_date_timestamp_neg_supported()
{
    return strtotime( 'Fri, 13 Dec 1950 20:45:54 UTC' ) === -601010046;
}

In your webserver, the strtotime( 'Fri, 13 Dec 1950 20:45:54 UTC' ) return value:
-600992046
but it should be value: -601010046

There are 5 hours (18000) between above two values (-601010046 and -600992046), which produce the problem: Types can not save the timestamp into database.

It is different value from -601010046, that means your webserver can not return the correct timestamp value, you will contact your webserver provider to correct it.
Relevant Documentation:
http://php.net/manual/en/function.strtotime.php

This support ticket is created Il y a 7 années et 9 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 16 réponses, has 2 voix.

Last updated by Sanny Il y a 7 années et 9 mois.

Assisted by: Luo Yang.

Auteur
Publications
#417085

Types custom date field is storing timestamp value into database, so it needs make sure your server is using correct server time, and introduce the function fields_date_timestamp_neg_supported() to check if the webserver can return correct timestamp value:
https://toolset.com/forums/topic/date-field-bug-on-save-get-error-please-enter-a-date-after-1-january-1970/#post-415771

I am not sure what is the custom PHP codes you mentioned above, but I don't think it will check your webserver timestamp settings.

#417289

I referred to forcing php to use a set timezone, on init of wp.
eg. date_default_timezone_set('Europe/Rome');
Still didnt work though, but I manage to fix by doing the following (if anyone has a similar issue):

Set your php.ini to the correct timezone, lat e long. (but this might not be enough, like in my case)
Set your apache config to the correct timezone.
If possible also your mysql config file.

I still think the script&Types should keep in consideration php.ini timezone settings (which were correct), instead of server/webserver time (which may vary and cant always be changed, especially on shared hosting).

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.