我正在尝试插入日期,让我们说CURDATE()一个sql DateTime字段.
我的日期格式为: 28/01/2008
当我尝试将其插入SQL时,我只得到零.
那么我怎样才能正确转换它?
Dan*_*man 24
$newdate = date('Y-m-d', strtotime($olddate));
Run Code Online (Sandbox Code Playgroud)
我正在尝试插入日期,让我们说CURDATE()到一个sql DateTime字段.
$timestamp = strtotime($old_date);
$mydate = date('Y-m-d H:i:s', $timestamp);
Run Code Online (Sandbox Code Playgroud)
由于您使用的是欧洲日期符号(dd/mm/yyyy),因此如果您不使用-或者,则strtotime函数将返回0(反过来将按日期转换为1970-01-01 ).作为分隔符.
因此,如果您想使用strtotime,那么您将不得不稍微更改日期字符串:
$olddate = '28/01/2008';
$newdate = strtotime(str_replace('/', '-', $olddate));
Run Code Online (Sandbox Code Playgroud)
$ newdate现在应该包含'2008-01-28'...
| 归档时间: |
|
| 查看次数: |
42587 次 |
| 最近记录: |