Jump to content

Archived

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

glenelkins

Compare Dates

Recommended Posts

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):

[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);
[/code]

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.

Share this post


Link to post
Share on other sites
You would pretty much just compare the timestamps...
[code=php:0]<?php
if($timestamp1 > $timestamp2) echo "Timestamp 1 is more recent than timestamp 2";
?>[/code]

Share this post


Link to post
Share on other sites
Provided $weddingdate and  $groupdate have the same format (timestamp, Ymd or 'Y-m-d') then simply

if ($weddingdate > $groupdate)

Share this post


Link to post
Share on other sites
I tried that many of times, it does not work

Share this post


Link to post
Share on other sites
You tried what many times? Please post the code that you tried and failed.

Ken

Share this post


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

[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");
}
[/code]

Share this post


Link to post
Share on other sites
use exit() after a location headers.
[code]
if ($weddingdate < $groupdate) {
header ("Location: index.php?page=2&message=Wedding Date Is Smaller Than The Group Tell Date");
exit();
}[/code]

Share this post


Link to post
Share on other sites

×

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.