Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

strtotime function in php is not working properly.

i am using code something like this


date("Y-m-d", strtotime($datevar));


it is working properly for recent dates but not working for years like 2060 or 1900 etc.

what is the reason?

Latest PHP date methods are not working in godaddy because of old version of php.


I want to insert it into mysql db

Thanks
Posted

1 solution

From PHP.NET documentation:
"The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer). However, before PHP 5.1.0 this range was limited from 01-01-1970 to 19-01-2038 on some systems (e.g. Windows)."

Use instead 'date("Y-m-d", strtotime($datevar));':
PHP
$dt = new DateTime($datevar);
$dt->format('Y-m-d');

OR
PHP
(new DateTime($datevar))->format('Y-m-d');
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900