简体   繁体   中英

strtotime is not working proper in php for future date?

When i am converting date from dmY in Ymd format. i am facing some issues for it.

example 19/08/1989 will convert into 1989/08/19 (it's correct),

19/08/2059 will convert into 1970/01/01 (it's not correct)

$re_date = date('Y-m-d', strtotime($_POST['re_date']));

Help me please. thanks in advance.

The maximum date allowed is Tue, 19 Jan 2038 03:14:07 UTC on 32 bit system

From the strotime docs :

Note:

The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC.

If you want it to work for 32 bit system then try like this using DateTime :

$date = new DateTime($_POST['re_date']);

echo $date->format('Y-m-d');

better trick

$str=explode('/',$_POST['re_date']);

$newdate = $str[2].'/'.$str[1].'/'.$str[0];

$ re_date = date('Y / m / d',strtotime($ _ POST ['re_date']));;

$date = $_POST['re_date'];
$date = str_replace("/", "-", $date);
$re_date = date('Y-m-d', strtotime($date));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM