View Full Version : dates

10-17-2008, 03:02 AM
as an attempt to understand dates a bit better i tried comparing dates with a field in a db . i have it wrong but i cant see it.
Im guessing its the date format as i i use date comparison <7 i get no results while if i use date comparison >7 than i get all the records echoed
the date field is timestamp, and i have hard coded a date (2) so as to try other formats easier.
i'd add a smiley but im too depressed
<?php function compareDate ($i_sFirstDate, $i_sSecondDate)
$arrFirstDate = explode ("/", $i_sFirstDate);
$arrSecondDate = explode ("/", $i_sSecondDate);

$intFirstMonth = $arrFirstDate[0];
$intFirstDay = $arrFirstDate[1];
$intFirstYear = $arrFirstDate[2];

$intSecondMonth = $arrSecondDate[0];
$intSecondDay = $arrSecondDate[1];
$intSecondYear = $arrSecondDate[2];

$intDate1 = mktime(12, 0, 0, intval($intFirstMonth), intval($intFirstDay), intval($intFirstYear));
$intDate2 = mktime(12, 0, 0, intval($intSecondMonth), intval($intSecondDay), intval($intSecondYear));

return $a = round(abs($intDate2 - $intDate1) / 86400);

do {

$date1= $record['date'];

$date2 = '10/21/2008';

if ( compareDate($date1, $date2)<7 ){
echo 'Newer than 7 days!';
echo $record['jbdes']."<br>";
} else {
echo 'Older than 7 days! ';
echo $record['jbdes']."<br>";
} while($record = mysql_fetch_array($query))

10-17-2008, 06:33 AM
whats the purpose of the loop?


are you wanting the number of days between 2 dates returned

10-17-2008, 06:39 AM
i want to return only the jobs i have added in the last 7 days,and no the number of days is not needed

10-18-2008, 05:35 AM
ha got it . at least i was right about being wron i had to convert mysql timestamp to unix. I forgot! i stopped using timestamps and now format the date I enter first.

10-18-2008, 06:12 AM
i was going to say that

after the couple of pints which interrupted our discussion

10-18-2008, 07:48 AM
i remembered after a few scotches