Click here to Skip to main content
11,712,454 members (71,796 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PHP MySQL
how can compare and get one day difference from current date on server with a date in the mysql database in a page in php
please help me.
Posted 7-Aug-12 22:12pm
Edited 7-Aug-12 22:13pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

if the date is in ISO standard format i.e. "yyyy-mm-dd" then you can verify the date simple condition. as example:
if('2012-10-11' < '2012-10-10')
{
 echo "not true";
}
 
if('2012-10-11' > '2012-10-10')
{
 echo "true";
}
 
if('2012-10-11' <= '2012-10-11')
{
 echo "true";
}

if it is not in ISO standard then convert it to ISO standard. By the way MySQL store date as ISO standard so don't worry about it. but if your input box does not receive it in ISO Standard then convert it.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

<?php $timezone = "Asia/Calcutta";
                                  if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
                  $d       =  date('Y-m-d');
                  $date    = $data['order_date'];
                  $e       =  date('Y-m-d',strtotime($date));
                 if($e == $d)
                                   {
echo "true";  ?>
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

<?php $timezone = "Asia/Calcutta";<br mode="hold" /??>                                  if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
                  $d       =  date('Y-m-d');
                  $date    = $data['order_date'];
                  $e       =  date('Y-m-d',strtotime($date));
                 if($e == $d)
                                   {
echo "true";  ?>
<?php }else{ ??>echo "false"; ?>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CHill60 335
1 Sergey Alexandrovich Kryukov 254
2 OriginalGriff 230
3 Andy Lanng 160
4 Maciej Los 130
0 CHill60 335
1 Sergey Alexandrovich Kryukov 245
2 OriginalGriff 230
3 Andy Lanng 160
4 Maciej Los 130


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 8 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100