将日期字符串转换为mysql datetime字段

编程入门 行业动态 更新时间:2024-10-17 20:24:42
本文介绍了将日期字符串转换为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字段

本文发布于:2023-07-09 21:30:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1088264.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   转换为   字符串   日期   datetime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!