Jump to content


Photo

strtotime


  • Please log in to reply
2 replies to this topic

#1 rocketman

rocketman
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 March 2006 - 11:33 PM

I have the following code:

$zi = date("l",strtotime($zi_de_calculat));

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

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 22 March 2006 - 11:39 PM

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

$zi = date("l",strtotime($zi_de_calculat));

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]

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);
?> 



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.


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 rocketman

rocketman
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 March 2006 - 11:56 PM

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');




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users