Jump to content

date function


Woodburn2006

Recommended Posts

i am trying to get a date from a database and comparing it to todays date, then depending on the date i want to display it or not display it. but i find that when using the time() function to return todays date in seconds, it is out of sinc with the returned results from the database this is the code that i use to get todays date in seconds:

[code]$today_seconds = time(); // todays date in seconds from jan 1, 1970[/code]

then this is the code that i use to sort out the dates that iwant once they have been returned from the database.

[code]while ($row_present = mysql_fetch_array($rs_present))
  {
  $startdate_present = $row_present[0];
  $exhibition_present = $row_present[1];
  $dateend_present = $row_present[2];
 
  $start_present = split("-",$startdate_present);
  $end_present = split("-",$dateend_present);
  $startdate_seconds_present = mktime(0,0,0,$start_present[0],$start_present[1],$start_present[2]);
  $enddate_seconds_present = mktime(0,0,0,$end_present[0],$end_present[1],$end_present[2]);
  if ($startdate_seconds_present < $today_seconds && $enddate_seconds_present > $today_seconds){echo "$startdate_present - $dateend_present: $exhibition_present<br>";}
 
  }[/code]

using this i always found that i would have odd outcomes. so i decided to change the date in the database to the same as todays date (31/7/2006) and see what the outcome in seconds was and this is what i got.

31/7/2006 from DB: 1215385200
31/7/2006 from system: 1154383906

it seems from this that one of the dates does not start from jan 1st 1970

any help would be very much appreciated.

thanks alot
Link to comment
https://forums.phpfreaks.com/topic/16149-date-function/
Share on other sites

thanks, that proves that the date coming from the system is ok, but when i use the same date and convert it with mktime() function i get a different rsult.

i used this code:

[code]<?php

$currdate = time();
$convert = date("d/m/Y",$currdate);

echo "Date = $convert<br>";
echo "Timestamp = $currdate<br>";

$todays_date = "01-08-2006";
 
$start_present = split("-",$todays_date);
$start = mktime(0,0,0,$start_present[0],$start_present[1],$start_present[2]);
echo "After mktime convert = $start";

?>[/code]

and i got this result:

Date = 01/08/2006
Timestamp = 1154388039
After mktime convert = 1136678400

any ideas why they are so different?
Link to comment
https://forums.phpfreaks.com/topic/16149-date-function/#findComment-66733
Share on other sites

Please show us how you are storing the data in the database. Use this code:
[code]<?php
while ($row_present = mysql_fetch_assoc($rs_present))
    echo '<pre>' . print_r($row_present,true) . '</pre>';
?>[/code]
Post the first record or so that displays on your screen. From that we will have a better handle on how to help you.

Ken
Link to comment
https://forums.phpfreaks.com/topic/16149-date-function/#findComment-66737
Share on other sites

thanks,

ive used

[code] $sql_new = "SELECT * FROM events WHERE CURDATE() >= startdate";

$result = mysql_query($sql_new, $connection);
    if (mysql_error()) { print "Database Error: $sql " . mysql_error(); }[/code]

and then used this to display it:

[code]while ($row_new = mysql_fetch_array($result)) {
echo $row_new[0];

}[/code]


but i get the result '23', what would the variable be?

i have tried $row_new[0]; and $startdate but '$startdate' has nothing and $row_new[0] has the value of '23'
Link to comment
https://forums.phpfreaks.com/topic/16149-date-function/#findComment-66774
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.