|
 |
|
รบกวนด่วนเรื่องเปรียบเทียบวันที่ ถ้าใน table มีชื่อฟิลด์ว่า deadline เก็บข้อมูลเป็นแบบ varchar เก็บวันที่ในรูปแบบ 08/04/2009 |
|
 |
|
|
 |
 |
|
แบบนี้ได้หรือเปล่า ง่าย ๆ ก่อน อย่าคิดลึกเกินเดี๋ยวมันจะทำไม่ทัน
Code (PHP)
<?php
//... ดึงข้อมูลจากฐานข้อมูลมาใส่ตัวแปร $rows ก่อนนะ
$t=explode("/",$rows["deadline"]);
$now=date("dmY");
$deadline=$t[0].$t[1].$t[2];
if ($deadline==$now){
echo "โชว์ข้อมูล";
}else{
echo "Not โชว์ข้อมูล";
}
?>
|
 |
 |
 |
 |
Date :
2009-04-08 11:21:40 |
By :
noomna19 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$deadline = 08/04/2009
if($deadline == date("d/m/Y"))
....
แต่จิงแล้วน่าจะเก็บค่า deadline เป็น date ไปเลย หรือเก็บเป็น YYYYMMDD มากกว่าน่ะครับ
|
 |
 |
 |
 |
Date :
2009-04-08 11:22:58 |
By :
windersun |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
// $date คือข้อมูลจากฐานข้อมูล deadline ที่เป็นรูปแบบ 01/01/2009
$day = explode("/",$date["deadline"]);
$arraydate = array($day[0].$day[1].$day[2];
if (checkdate($arraydate [0],$arraydate [1],$arraydate [2])){
echo "Yes";
}else{
echo "No";
}
?>
ลองดูนะครับ
|
 |
 |
 |
 |
Date :
2009-04-08 20:54:32 |
By :
mosaddzero |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โทษทีครับผิดนิดหน่อย
Code (PHP)
<?php
// $date คือข้อมูลจากฐานข้อมูล deadline ที่เป็นรูปแบบ 01/01/2009
$day = explode("/",$date["deadline"]);
$arraydate = array($day[0].$day[1].$day[2];
if (checkdate($arraydate [1],$arraydate [0],$arraydate [2])){
echo "Yes";
}else{
echo "No";
}
?>
|
 |
 |
 |
 |
Date :
2009-04-09 18:12:25 |
By :
mosaddzero |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำไมไม่เก็บเป็น datetime จะงน่าจะดึงมาทำงานง่ายกว่านะ
|
 |
 |
 |
 |
Date :
2009-04-11 16:02:52 |
By :
sillyman24 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|