2017-09-24 9 views
0

に格納されている日付&時間以上であれば、現在の時刻ISTMysqlエコー現在の日時は、MySQL

に保存された時間以上であれば、いくつかのテキストは、私がPHPechoにいくつかのテキストをしようとしている時間のストアド:2017-09-24 16:36:15

現在の時刻(IST):2017-09-24 16:46:15

は、私が試した:

<?php 
require_once 'vclass.php'; 
require_once 'message.php'; 


$vreg = new Validation(); 

$stmt = $vreg->runQuery("SELECT * FROM validation WHERE vid=1"); 
$stmt->execute(); 
$row = $stmt->fetch(PDO::FETCH_ASSOC); 
$vusrmaile = $row['svdate']; 
$vusrmail = $row['vdate']; 
date_default_timezone_set('Asia/Calcutta'); 
$date = date('Y-m-d h:i:s ', time()); 

      if($date > $vusrmail){ 
       $msg = " 
       <div class='alert alert-error'> 

        <strong><center>Process</center></strong> 
       </div> 
       "; 

     } 
?> 

上記のコードから、期待通りの結果が得られません。

+1

使用DateTimeオブジェクトをそうすることをどのように2 – Qirel

+0

@Qirelを比較しますか? –

+1

'$ date = date( 'Y-m-d H:i:s'、time());'は24時間クロック用です。小さなhは12時間用です –

答えて

0

あなたはUnix TimeにあなたのMySQLデータベースからタイムスタンプを変換し、(Unixの時間で表される)現在時刻と比較することができます:

<?php 
require_once 'vclass.php'; 
require_once 'message.php'; 


$vreg = new Validation(); 

$stmt = $vreg->runQuery("SELECT * FROM validation WHERE vid=1"); 
$stmt->execute(); 
$row = $stmt->fetch(PDO::FETCH_ASSOC); 
$vusrmaile = $row['svdate']; 
$vusrmail = strtotime($row['vdate']); // Convert MySQL datetime string to Unix Time (this will depend on current timezone) 
$date = time(); // Current Unix time (this is independent of timezone) 

      if($date > $vusrmail){ 
       $msg = " 
       <div class='alert alert-error'> 

        <strong><center>Process</center></strong> 
       </div> 
       "; 

     } 
?> 
+0

答えてくれてありがとうございますが、私は** Raymondの**答えに行ってきました。小さな質問...「アメリカ/ニューヨーク」のシステムにあるデータベースに 'IST'の' date&time'を挿入できますか? **「アメリカ/ニューヨーク」と「IST」の違いは+09:30です** –

関連する問題