Forums

PHP

This topic is locked

Comparing Dates

Posted 13 Jan 2003 14:07:35
1
has voted
13 Jan 2003 14:07:35 Julio Taylor posted:
Hello

i want to make a function that basically checks which date is more recent, like so:

<pre id=code><font face=courier size=2 id=code>
&lt;?php
$VarDate1 = "13/1/2003"
$VarDate2 = "17/12/2002"

if($VarDate1 &gt; Vardate2)
{
print("first date is laterr";
}
else
{
print("second date is later);
}
?&gt;
</font id=code></pre id=code>

however the bastard program only calculates the first number of the date, (i.e. 17 in this case) and amazingly and self-righteously decides that the 2002 date is in fact more recent than the 2003 one.

How do i make the program choose the right date?

Thanks!

------------------------
Julio

PHP | MySQL | UD4

ICQ: 19735247

Replies

Replied 14 Jan 2003 06:39:11
14 Jan 2003 06:39:11 Nicholas Bennett replied:
hi poolio try this:

&lt;?php

$date1 = "13/1/2003";
$date2 = "17/12/2002";

if(strtotime($date1) &gt; strtotime($date2))
{
print("first date is later.";
}
else
{
print("second date is later.";
}
?&gt;

have a look at www.php.net/manual/en/function.strtotime.php to see how the strtotime() function works.

Edited by - nickuk on 14 Jan 2003 06:44:03
Replied 14 Jan 2003 09:54:04
14 Jan 2003 09:54:04 Julio Taylor replied:
ninkuk,

thanks a lot mate, it works a treat! <img src=../images/dmxzone/forum/icon_smile_cool.gif border=0 align=middle>

------------------------
Julio

PHP | MySQL | UD4

ICQ: 19735247

Reply to this topic