duanjigua5753 2010-12-21 15:21 采纳率: 0%
浏览 63
已采纳

格式化数据库的日期编号

Not sure if I should edit this question or just ask another question in a different post. I am having a hard time doing the reverse of what I originally asked. How do I get the "date number" in php. I want to assign the current date number to a variable to so I can use it in my query to compare what is already in the database.

I can not see the SQL Server database but I am connecting to it using ODBC and PHP on a Linux box. I was told that the field "meeting_start" was a "Date Number". When I get the value of the "meeting_start" the format looks like this.

2010-08-24 20:00:00.000 

I need both the date and time but for different parts of my function. Is there a way to extract the data for the date and save to a variable and then extract the data for the time and save to a different variable. Below is me trying to take a stab at it.

$time_date_data = "2010-08-24 20:00:00.000"

$meeting_date = get_date($time_date_data); 

$meeting_time = get_time($time_date_data);
  • 写回答

4条回答 默认 最新

  • du7979 2010-12-21 15:25
    关注

    You're looking for the date function:

    $meeting_date = date('Y-m-d', strtotime($time_date_data));
    $meeting_time = date('H:i', strtotime($time_date_data));
    

    For $time_date_data = '2010-08-24 20:00:00.000', you'll get:

    $meeting_date = '2010-08-24';
    $meeting_time = '20:00';
    

    You can change the format by changing the first argument to date() according to the docs...

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

报告相同问题?