Jump to content

Archived

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

rocketman

strtotime

Recommended Posts

I have the following code:

[code]
$zi = date("l",strtotime($zi_de_calculat));
[/code]

Where $zi_de_calculat it's a date in the format mm/dd/yy

03/25/06 becomes after applying strtotime 1143237600 and $zi becomes Saturday
03/26/06 becomes after applying strtotime 1143320400 and $zi becomes Saturday instead of Sunday

Does anyone know the solution to this problem or the cause.

Note: For all the other days of the week works just fine, only Sunday is replaced by Saturday.

Thx

Share this post


Link to post
Share on other sites
[!--quoteo(post=357436:date=Mar 22 2006, 11:33 PM:name=Rocketman)--][div class=\'quotetop\']QUOTE(Rocketman @ Mar 22 2006, 11:33 PM) [snapback]357436[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I have the following code:

[code]
$zi = date("l",strtotime($zi_de_calculat));
[/code]

Where $zi_de_calculat it's a date in the format mm/dd/yy

03/25/06 becomes after applying strtotime 1143237600 and $zi becomes Saturday
03/26/06 becomes after applying strtotime 1143320400 and $zi becomes Saturday instead of Sunday

Does anyone know the solution to this problem or the cause.

Note: For all the other days of the week works just fine, only Sunday is replaced by Saturday.

Thx
[/quote]

[code]
In PHP 4.3.10(Suse Linux 9.2) strtotime() seems to sometimes resolve incorrect month values.
e.g.:
<?
   $day = strftime ("%d", strtotime("-$day days"));
   $month = strftime ("%m", strtotime("-$day days"));
   $year = strftime ("%Y", strtotime("-$day days"));
?>
Result: $month is sometimes: expected month-1

php.net bug-reporting systems says: "problem will be fixed in php5 not any londer in php4!".

Workarround in php4 to savely get the correct values for example above:

<?
   $date = strftime ("%d.%m.%Y", strtotime("-$day days"));
   list($day, $month, $year) = split('[/.]', $date);
?>

[/code]


ps [!--sizeo:5--][span style=\"font-size:18pt;line-height:100%\"][!--/sizeo--]read[!--sizec--][/span][!--/sizec--]
[a href=\"http://uk.php.net/strtotime\" target=\"_blank\"]http://uk.php.net/strtotime[/a]
good luck.

Share this post


Link to post
Share on other sites
Found the solution using MySQL

//This will return the day of the week in numerical format (i.e. "0" Monday to "6" Sunday)
SELECT WEEKDAY('2003-01-01');

//This will return the day of the week in numerical format (i.e. "1" Sunday to "7" Saturday)
SELECT DAYOFWEEK('2003-01-01');

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.