Jump to content


Photo

Compare Dates


  • Please log in to reply
6 replies to this topic

#1 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 13 July 2006 - 07:07 AM

Hi

So i take 3 dates from a form. These are then run through a save script into the database. here is the code to take one of the dates from the form and convert to a unix stamp (the other 2 date boxes work the same):

$temp_wd = explode("-",$_POST['date']);
$wed = mktime(0,0,0,$temp_wd[1],$temp_wd[0],$temp_wd[2]);
$weddingdate = date("Y-m-d",$wed);

now the next date comes as vars; $temp_gd, $group and $groupdate. How can I compare these two dates in an if statement? I want to test if $weddingdate > $groupdate.
http://thewebsolutionprovider.com - A Solution For Everything Web!

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 13 July 2006 - 07:39 AM

You would pretty much just compare the timestamps...
<?php
if($timestamp1 > $timestamp2) echo "Timestamp 1 is more recent than timestamp 2";
?>


#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 13 July 2006 - 07:41 AM

Provided $weddingdate and  $groupdate have the same format (timestamp, Ymd or 'Y-m-d') then simply

if ($weddingdate > $groupdate)
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 13 July 2006 - 02:48 PM

I tried that many of times, it does not work
http://thewebsolutionprovider.com - A Solution For Everything Web!

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 13 July 2006 - 03:01 PM

You tried what many times? Please post the code that you tried and failed.

Ken

#6 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 15 July 2006 - 09:55 AM

Here is the code, its does not work. Its supposed to return with header() but it carries on the code

$temp_wd = explode("-",$_POST['date']);
$wed = mktime(0,0,0,$temp_wd[1],$temp_wd[0],$temp_wd[2]);
$weddingdate = date("Y-m-d",$wed);

$temp_gd = explode("-",$_POST['groupdate']);
$group = mktime(0,0,0,$temp_gd[1],$temp_gd[0],$temp_gd[2]);
$groupdate = date("Y-m-d",$group);
	
//$groupremind = $_POST['groupremind'];
	
if ($_POST['reminderdate'] != "") {
  $temp_grd = explode ("-",$_POST['reminderdate']);
  $remind = mktime(0,0,0,$temp_grd[1],$temp_grd[0],$temp_grd[2]);
  $groupreminddate = date("Y-m-d",$remind);
} else {
  $groupreminddate = "00-00-0000";
}
		
if ($weddingdate < $groupdate) {
 header ("Location: index.php?page=2&message=Wedding Date Is Smaller Than The Group Tell Date");
}

http://thewebsolutionprovider.com - A Solution For Everything Web!

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 15 July 2006 - 10:15 AM

use exit() after a location headers.
if ($weddingdate < $groupdate) {
 header ("Location: index.php?page=2&message=Wedding Date Is Smaller Than The Group Tell Date");
 exit();
}

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users