dqwh1119 2013-08-12 08:59
浏览 18
已采纳

如何在PHP中获取日期字段? [重复]

This question already has an answer here:

How can I get the value of a date in php? For example I have a date like this:

$date = "2013-01-29";

And what I want is to get the year the month and the day and assign it in a variable.

Example:

$year = "2013";

$month = "01";

$day = "29";

How can I do this?

</div>
  • 写回答

5条回答 默认 最新

  • duanjieyi6582 2013-08-12 09:01
    关注

    Use strtotime(), which converts a string of various formats to a date. It can detect various formats of dates:

    $date_unix = strtotime($date);
    $year = date("Y", $date_unix);
    $month = date("m", $date_unix);
    $day = date("d", $date_unix);
    

    Also see date() for a list of all modifiers.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?