2010-12-22 89 views
0

这个问题去along with another one of my post,我已经接受了保存日期数目在PHP变量

如何获得“约会号”在PHP

2010-08-24 20:00:00.000 

我想当前日期数分配给一个变量$ current_date_num,所以我可以在我的查询中使用它来比较数据库中已有的内容。

$query ="SELECT * FROM Reservations WHERE [Room_ID] = '$field' AND [Meeting Start] > '$current_date_num' ORDER BY [Meeting Start] asc "; 
+0

“我的另一篇文章”你的意思是这一个http://stackoverflow.com/questions/4457543/add-date-to-mysql-from-php-for-sorting-later?你可以链接 – 2010-12-22 15:53:49

+0

其实它的http://stackoverflow.com/questions/4500786/format-date-number-from-database – Denoteone 2010-12-22 16:20:49

回答

1

如果你只在数据库中使用它,可以考虑NOW

1

为了获取当前日期数以上格式,你会怎么做:

echo date("Y-m-d H:i:s.u") 
+0

如果我这样做它是一个字符串?我应该可以将它与数据库中其他日期相同的格式进行比较。 – Denoteone 2010-12-22 16:23:35

0

好,你可以得到这样的..前的日期编号。来自php.net http://php.net/manual/en/function.date.php

<?php 
// Assuming today is March 10th, 2001, 5:16:18 pm, and that we are in the 
// Mountain Standard Time (MST) Time Zone 

    $today = date("F j, Y, g:i a");     // March 10, 2001, 5:16 pm 
    $today = date("m.d.y");       // 03.10.01 
    $today = date("j, n, Y");      // 10, 3, 2001 
    $today = date("Ymd");       // 20010310 
    $today = date('h-i-s, j-m-y, it is w Day');  // 05-16-18, 10-03-01, 1631 1618 6 Satpm01 
    $today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // it is the 10th day. 
    $today = date("D M j G:i:s T Y");    // Sat Mar 10 17:16:18 MST 2001 
    $today = date('H:m:s \m \i\s\ \m\o\n\t\h');  // 17:03:18 m is month 
    $today = date("H:i:s");       // 17:16:18 
    ?> 
0

如果你想从用户侧 在页面中使用指定它它这样

strtotime($time1)