In the strtotime notes, it says that strtotime returns -1 previous to
php5, but if I do:
If( strtotime( '1/2009') == -1 )
{
Echo 'false';
}
Else
{
Echo 'true';
}
If( strtotime( '1/2009') === -1 )
{
Echo 'false';
}
Else
{
Echo 'true';
}
If( strtotime( '1/2009') == '-1' )
{
Echo 'false';
}
Else
{
Echo 'true';
}
All of those echo true, how do I determine if strtotime has failed or
not?
Mark
-----Original Message-----
From: Mark Steudel
Sent: Wednesday, August 02, 2006 9:55 AM
To: Mark Steudel; PHP Mailing Lists
Subject: RE: [PHP] date(n/Y) strtotime
Ok so actually I didn't solve it. Php5, this works, but php 4.4.1 and
4.4.0 don't handle this correctly. Here's my code I'm running on each
box:
function expDate2str( $date )
{
if( !($sDate = strtotime( $date ) ) )
{
echo "Invalid, blowing up date<br />";
// exploded date
$eDate = explode( '/', $date );
// string date
$sDate = strtotime( date( "Y-m-d", mktime( 0, 0, 0,
$eDate[0], 1, $eDate[1] ) ) );
}
else
{
echo "valid<br/>";
}
echo "In: " .$date ."<br />Out: ". date( "Y-m-d", $sDate ) ."<br
/><br />";
}
expDate2str('1/2009');
expDate2str( date( "n/Y"));
Here are the results:
Php 5.1.2
Invalid, blowing up date
In: 1/2009
Out: 2009-01-01
Invalid, blowing up date
In: 8/2006
Out: 2006-08-01
PHP 4.4.1
Valid
In: 1/2009
Out: 2011-07-02
Valid
In: 8/2006
Out: 2012-01-27
PHP 4.4.0
Valid
In: 1/2009
Out: 2011-07-02
Valid
In: 8/2006
Out: 2012-01-27
Any work around with these types of dates on php4?
Mark
-----Original Message-----
From: Mark Steudel
Sent: Wednesday, August 02, 2006 9:46 AM
To: PHP Mailing Lists
Subject: [PHP] date(n/Y) strtotime
I've always been really amazed at how well strtotime works, but recently
ran into an issue where it couldn't figure out the date if it was a cc
exp date in long format, e.g. 1/2009. I was curious if anyone else has
run into this and how did they get around it, here was my solution:
function expDate2str( $date )
{
if( !($sDate = strtotime( $date ) ) )
{
// exploded date
$eDate = explode( '/', $date );
// string date we hard code the day to 1
$sDate = strtotime( date( "Y-m-d", mktime( 0, 0, 0,
$eDate[0], 1, $eDate[1] ) ) );
}
return $sDate;
}
Thanks, Mark
--------------------------------------------------------------
Mark Steudel
Web Applications Developer
555 Dayton St
Suite A
Edmonds, WA 98020
p: 425.741.7014
e: [EMAIL PROTECTED]
w: http://www.netriver.net
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php