将日期字符串转换为mysql datetime字段 [英] convert date string to mysql datetime field

查看:464
本文介绍了将日期字符串转换为mysql datetime字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆记录,日期格式为字符串,例如'04/17/2009'

I have a bunch of records with dates formatted as a string such as '04/17/2009'

我想将它们转换为mysql datetime字段

I want to convert them to a mysql datetime field

我计划使用foreach循环读取旧的日期值,并将新格式化的值插入每条记录的新字段中

I plan to use a foreach loop to read the old date value and insert the newly formatted value into a new field in each record

什么是转换字符串的最佳方法...我认为php可能有一种自动完成此方法的方法?

what would be the best way to convert that string...I thought php might have a way to do it automatically?

谢谢

推荐答案

首先,将字符串转换为时间戳:

First, convert the string into a timestamp:

$timestamp = strtotime($string);

然后做

date("Y-m-d H:i:s", $timestamp);

这篇关于将日期字符串转换为mysql datetime字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆