date() method, “A non well formed numeric value encountered” does not want to format a date passed in $_POST

前端 未结 1 394
迷失自我
迷失自我 2020-12-03 10:20

I unfortunately can\'t use DateTime() as the server this project is on is running PHP v.5.2.

the line in question:

$aptnDate2 = date(\'Y         


        
相关标签:
1条回答
  • 2020-12-03 10:51

    From the documentation for strtotime():

    Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.

    In your date string, you have 12-16-2013. 16 isn't a valid month, and hence strtotime() returns false.

    Since you can't use DateTime class, you could manually replace the - with / using str_replace() to convert the date string into a format that strtotime() understands:

    $date = '2-16-2013';
    echo date('Y-m-d', strtotime(str_replace('-','/', $date))); // => 2013-02-16
    
    0 讨论(0)
提交回复
热议问题