2010-12-22 88 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)