Jump to content

Stuck at unexpected issue :( DATE/TIME


radiations3

Recommended Posts

Hi,

I am using the following code in order to calculate differnece between given time and current system time/date

the issue that i am facing is that if i run the following 1st code it runs absolutely perfect without an error but when i put this code in the file where i actually have to use this code then its not displaying the time left correctly

I am passin value through the database:

 

<?php
// I put the following date values from the database in the 2nd code but its displaying the days left as 2275 where as if i run this peice of code it returning 0 days left which is correct 
  $check = '08/18/2011 19:50:00'; // Set it to the recordset or a variable from where the date is comming from the specific field from database
  $date = strtotime($check); // Just put in between these two parenthesis the date, wherever it may come from.
  echo $date;
  $countdown = date('Y-m-d h:i:s',$date); 
  $event_year = date('Y',$date);
  $event_month = date('n',$date);
  $event_day = date('j',$date);
  $event_hour = date('G',$date);
  $event_mins = date('i',$date);
  $event_sec  = date('s',$date);
     
  $difference = mktime ($event_hour,$event_mins,$event_sec,$event_month,$event_day,$event_year) - time();
  $days_left = floor($difference/60/60/24);
  $hours_left = floor(($difference - $days_left*60*60*24)/60/60);
  $minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
   print "Today's Date is. ".date('Y-m-d h:i:s',time()) . '<br />';
   
   print "Countdown Date is. ".$countdown . '<br />';
   print $days_left . ' days<br />';
   print $hours_left . ' Hours <br />';
   print $minutes_left  . ' Minutes';
  ?>

 

The following code is the place where i actually need this code:

 

<?php
  $check = $row_Recordset1['end_date']; // Set it to the recordset or a variable from where the date is comming from the specific field from database
  $date = strtotime($check); // Just put in between these two parenthesis the date, wherever it may come from.
  echo $check;  // the result is assigning absolutely correctly to $check
  $countdown = date('Y-m-d h:i:s',$date); 
  $event_year = date('Y',$date);
  $event_month = date('n',$date);
  $event_day = date('j',$date);
  $event_hour = date('G',$date);
  $event_mins = date('i',$date);
  //$event_sec  = date('s',$date);
     
  $difference = mktime ($event_hour,$event_mins,$event_month,$event_day,$event_year) - time();
  $days_left = floor($difference/60/60/24);
  $hours_left = floor(($difference - $days_left*60*60*24)/60/60);
  $minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
   //print "Today's Date is. ".date('Y-m-d h:i:s',time()) . '<br />';
   
   //print "Countdown Date is. ".$countdown . '<br />';
   //print $days_left . ' days<br />';
   //print $hours_left . ' Hours <br />';
   //print $minutes_left  . ' Minutes';
  ?>
              <?php echo $days_left; ?> Days : <?php echo $hours_left; ?> Hours : <?php echo $minutes_left; ?> Minutes</p>

Link to comment
https://forums.phpfreaks.com/topic/245048-stuck-at-unexpected-issue-datetime/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.