RE: [PHP] compare dates

2011-12-01 Thread Marc Fromm
Thanks. I'm stuck using 5.1.6. Matijn reply worked by using the unix timestamp.

-Original Message-
From: Maciek Sokolewicz [mailto:tula...@gmail.com] On Behalf Of Maciek 
Sokolewicz
Sent: Thursday, December 01, 2011 12:57 PM
To: Marc Fromm
Cc: Floyd Resler
Subject: Re: [PHP] compare dates

On 01-12-2011 02:17, Floyd Resler wrote:
>
> On Nov 30, 2011, at 5:04 PM, Matijn Woudt wrote:
>
>> On Wed, Nov 30, 2011 at 11:00 PM, Marc Fromm  wrote:
>>> I'm puzzled why the if statement executes as true when the first date 
>>> (job_closedate) is not less than the second date (now).
>>> The if statement claims that "12/02/2011" is less than "11/30/2011".
>>>
>>> if (date("m/d/Y",strtotime($jobs_closedate))<= 
>>> date("m/d/Y",strtotime("now"))){
>>
>> You're comparing strings here, try to compare the unix timestamp:
>>
>> if (strtotime($jobs_closedate)<= strtotime("now")){
>>
>> That'll probably do what you want..
>>
>> Matijn
>>
>
> Another way to do it would be:
> if(strtotime($jobs_closedate)<=time()) { }
>
> or
>
> if(date("Y-m-d",strtotime($job_closedate))<=date("Y-m-d",time()) { }
>
> Take care,
> Floyd


As of PHP 5.2.2 direct comparison of DateTime objects is also possible. So:
$closeDate = new DateTime($jobs_closedate); $now = new DateTime('now'); 
if($closeDate < $now) {
echo $closeDate->format('m/d/Y'); // output in US date format
echo $now->format('m/d/Y'); // output in US date format
$error .= "The close date must be later than today's date, " . 
$now->format('m/d/Y') . "\n";
}

This, IMO is a lot prettier.
- Tul



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] compare dates

2011-12-01 Thread Maciek Sokolewicz

On 01-12-2011 02:17, Floyd Resler wrote:


On Nov 30, 2011, at 5:04 PM, Matijn Woudt wrote:


On Wed, Nov 30, 2011 at 11:00 PM, Marc Fromm  wrote:

I'm puzzled why the if statement executes as true when the first date 
(job_closedate) is not less than the second date (now).
The if statement claims that "12/02/2011" is less than "11/30/2011".

if (date("m/d/Y",strtotime($jobs_closedate))<= 
date("m/d/Y",strtotime("now"))){


You're comparing strings here, try to compare the unix timestamp:

if (strtotime($jobs_closedate)<= strtotime("now")){

That'll probably do what you want..

Matijn



Another way to do it would be:
if(strtotime($jobs_closedate)<=time()) {
}

or

if(date("Y-m-d",strtotime($job_closedate))<=date("Y-m-d",time()) {
}

Take care,
Floyd



As of PHP 5.2.2 direct comparison of DateTime objects is also possible. So:
$closeDate = new DateTime($jobs_closedate);
$now = new DateTime('now');
if($closeDate < $now) {
   echo $closeDate->format('m/d/Y'); // output in US date format
   echo $now->format('m/d/Y'); // output in US date format
   $error .= "The close date must be later than today's date, " . 
$now->format('m/d/Y') . "\n";

}

This, IMO is a lot prettier.
- Tul


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] compare dates

2011-12-01 Thread Maciek Sokolewicz

On 01-12-2011 02:17, Floyd Resler wrote:


On Nov 30, 2011, at 5:04 PM, Matijn Woudt wrote:


On Wed, Nov 30, 2011 at 11:00 PM, Marc Fromm  wrote:

I'm puzzled why the if statement executes as true when the first date 
(job_closedate) is not less than the second date (now).
The if statement claims that "12/02/2011" is less than "11/30/2011".

if (date("m/d/Y",strtotime($jobs_closedate))<= 
date("m/d/Y",strtotime("now"))){


You're comparing strings here, try to compare the unix timestamp:

if (strtotime($jobs_closedate)<= strtotime("now")){

That'll probably do what you want..

Matijn



Another way to do it would be:
if(strtotime($jobs_closedate)<=time()) {
}

or

if(date("Y-m-d",strtotime($job_closedate))<=date("Y-m-d",time()) {
}

Take care,
Floyd




As of PHP 5.2.2 direct comparison of DateTime objects is also possible. So:
$closeDate = new DateTime($jobs_closedate);
$now = new DateTime('now');
if($closeDate < $now) {
   echo $closeDate->format('m/d/Y'); // output in US date format
   echo $now->format('m/d/Y'); // output in US date format
   $error .= "The close date must be later than today's date, " . 
$now->format('m/d/Y') . "\n";

}

This, IMO is a lot prettier.
- Tul

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] compare dates

2011-12-01 Thread Maciek Sokolewicz

On 01-12-2011 02:17, Floyd Resler wrote:


On Nov 30, 2011, at 5:04 PM, Matijn Woudt wrote:


On Wed, Nov 30, 2011 at 11:00 PM, Marc Fromm  wrote:

I'm puzzled why the if statement executes as true when the first date 
(job_closedate) is not less than the second date (now).
The if statement claims that "12/02/2011" is less than "11/30/2011".

if (date("m/d/Y",strtotime($jobs_closedate))<= 
date("m/d/Y",strtotime("now"))){


You're comparing strings here, try to compare the unix timestamp:

if (strtotime($jobs_closedate)<= strtotime("now")){

That'll probably do what you want..

Matijn



Another way to do it would be:
if(strtotime($jobs_closedate)<=time()) {
}

or

if(date("Y-m-d",strtotime($job_closedate))<=date("Y-m-d",time()) {
}

Take care,
Floyd




As of PHP 5.2.2 direct comparison of DateTime objects is also possible. So:
$closeDate = new DateTime($jobs_closedate);
$now = new DateTime('now');
if($closeDate < $now) {
   echo $closeDate->format('m/d/Y'); // output in US date format
   echo $now->format('m/d/Y'); // output in US date format
   $error .= "The close date must be later than today's date, " . 
$now->format('m/d/Y') . "\n";

}

This, IMO is a lot prettier.
- Tul

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] compare dates

2011-11-30 Thread Floyd Resler

On Nov 30, 2011, at 5:04 PM, Matijn Woudt wrote:

> On Wed, Nov 30, 2011 at 11:00 PM, Marc Fromm  wrote:
>> I'm puzzled why the if statement executes as true when the first date 
>> (job_closedate) is not less than the second date (now).
>> The if statement claims that "12/02/2011" is less than "11/30/2011".
>> 
>>if (date("m/d/Y",strtotime($jobs_closedate)) <= 
>> date("m/d/Y",strtotime("now"))){
> 
> You're comparing strings here, try to compare the unix timestamp:
> 
> if (strtotime($jobs_closedate) <= strtotime("now")){
> 
> That'll probably do what you want..
> 
> Matijn
> 

Another way to do it would be:
if(strtotime($jobs_closedate)<=time()) {
}

or

if(date("Y-m-d",strtotime($job_closedate))<=date("Y-m-d",time()) {
}

Take care,
Floyd



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] compare dates

2011-11-30 Thread Matijn Woudt
On Wed, Nov 30, 2011 at 11:00 PM, Marc Fromm  wrote:
> I'm puzzled why the if statement executes as true when the first date 
> (job_closedate) is not less than the second date (now).
> The if statement claims that "12/02/2011" is less than "11/30/2011".
>
>                if (date("m/d/Y",strtotime($jobs_closedate)) <= 
> date("m/d/Y",strtotime("now"))){

You're comparing strings here, try to compare the unix timestamp:

if (strtotime($jobs_closedate) <= strtotime("now")){

That'll probably do what you want..

Matijn

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] compare dates

2011-11-30 Thread Marc Fromm
I'm puzzled why the if statement executes as true when the first date 
(job_closedate) is not less than the second date (now).
The if statement claims that "12/02/2011" is less than "11/30/2011".

if (date("m/d/Y",strtotime($jobs_closedate)) <= 
date("m/d/Y",strtotime("now"))){

echo date("m/d/Y",strtotime($jobs_closedate)); // displays - 
12/02/2011
echo date("m/d/Y",strtotime("now")); // 
displays - 11/30/2011

$error.="The close date must be later than 
today's date, " . date("m/d/Y",strtotime("now")) . ".\n";
}

If the first date is "11/16/2011" the if statement also executes as true which 
is correct since "11/16/2011" is less than "11/30/2011".

Marc


Re: [PHP] Compare dates

2003-09-29 Thread Leif K-Brooks
Shaun wrote:

How can I compare two dates with PHP, to see if one date occurred before the
other?
 

Convert them to a timestamps (strtotime()), then just compare them:

$date1 = 'september 10th 2003';
$date2 = 'september 20th 2003';
$date1_ts = strtotime($date1);
$date2_ts = strtotime($date2);
if($date1_ts < $date2_ts){
echo 'Date 1 is before date 2.';
}else{
echo 'Date 2 is before date 1.';
}
--
The above message is encrypted with double rot13 encoding.  Any unauthorized attempt 
to decrypt it will be prosecuted to the full extent of the law.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Compare dates

2003-09-29 Thread Blue Prawn
> How can I compare two dates with PHP, to see if one date occurred before
> the other?

probably not the best way but:

if the date is formated like this 20030929 (today) 20030928 (yesterday)
I think it is quite easy:
if ( (int)$today > (int)$yesterday )
or perhaps like this:
if ( strcmp($today, $yesterday) )

if you have to change the format, you can use :
http://www.php.net/manual/en/function.preg-replace.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Compare dates

2003-09-29 Thread chris . neale
I always use Unix timestamps until I need to format it to a (what's the
word) date for presentation.

Then you can just to a if $x < $y then it happened before $y.

look for mktime(), time(), date() in the manual.

C

-Original Message-
From: Shaun [mailto:[EMAIL PROTECTED]
Sent: 29 September 2003 10:52
To: [EMAIL PROTECTED]
Subject: [PHP] Compare dates


Hi,

How can I compare two dates with PHP, to see if one date occurred before the
other?

Thanks for your help

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
 
If you are not the intended recipient of this e-mail, please preserve the
confidentiality of it and advise the sender immediately of any error in
transmission. Any disclosure, copying, distribution or action taken, or
omitted to be taken, by an unauthorised recipient in reliance upon the
contents of this e-mail is prohibited. Somerfield cannot accept liability
for any damage which you may sustain as a result of software viruses so
please carry out your own virus checks before opening an attachment. In
replying to this e-mail you are granting the right for that reply to be
forwarded to any other individual within the business and also to be read by
others. Any views expressed by an individual within this message do not
necessarily reflect the views of Somerfield.  Somerfield reserves the right
to intercept, monitor and record communications for lawful business
purposes.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Compare dates

2003-09-29 Thread Shaun
Hi,

How can I compare two dates with PHP, to see if one date occurred before the
other?

Thanks for your help

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Compare dates

2003-06-05 Thread Shaun
Hi,

I have two dates retrieved from a database stored as variables: $mindate and
$maxdate, how can i compare the two with PHP so i can loop and increment
i.e.

while($mindate < $maxdate){
  //do some stuff
  $mindate++;
}

Thanks for your help



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php