Bug #17965 Updated: Strftime returns day of the week 1 to high after 23-6-2002

From: Date: Fri, 28 Jun 2002 01:14:28 +0000
Subject: Bug #17965 Updated: Strftime returns day of the week 1 to high after 23-6-2002
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-12290@lists.php.net to get a copy of this message
ID: 17965 Updated by: sniper@php.net Reported By: didier.peereboomvoller@o2.com -Status: Open +Status: Bogus Bug Type: Date/time related Operating System: Linux 2.4.?? PHP Version: 4.1.2 New Comment: $timestamp = mktime($b[3] , $b[5] , $b[6] , $b[2] , $b[3] , $b[1]); This should be: $timestamp = mktime($b[4] , $b[5] , $b[6] , $b[2] , $b[3] , $b[1]); The first parameter to mktime should be HOUR...so of course it started misbehaving after 23rd.. Not a bug. (and you should also consider what Rasmus noticed, 09 != 9) Previous Comments: ------------------------------------------------------------------------ [2002-06-27 04:01:50] rasmus@php.net Well, one obvious problem here is that you are passing in 09 as one of the arguments to mktime. 09 is not a valid number. Any number that starts with 0 is treated as an octal which obviously doesn't have a 9 in it. This may not be the problem since it would only affect the minute-arg of the example you provided. ------------------------------------------------------------------------ [2002-06-27 03:51:56] didier.peereboomvoller@o2.com // As short as I can get it. // turn sql type date into timestamp ereg("([0-9]*)-([0-9]*)-([0-9]*) ([0-9]*):([0-9]*):([0-9]*)" , "2002-06-25 11:09:12" , $b) $timestamp = mktime($b[3] , $b[5] , $b[6] , $b[2] , $b[3] , $b[1]); print(strftime("DAG 1 = maandag [%u] DAG 0 = zondag [%w]" , $timestamp) . "\n"); ------------------------------------------------------------------------ [2002-06-26 15:06:44] sniper@php.net Please provide a _short_ example script without anything that isn't relevant. (ie. such script that can be run in command line too) Also, try this snapshot first: http://snaps.php.net/php4-latest.tar.gz ------------------------------------------------------------------------ [2002-06-26 09:42:35] didier.peereboomvoller@o2.com It maybe that the error lies in mktime instead. ------------------------------------------------------------------------ [2002-06-25 05:57:49] didier.peereboomvoller@o2.com I use strftime("%y" , $var) to get the day of the week to display in a website. http://nieuws.online.o2.nl (dutch site, designed for a pda) However since 23-6-2002 (D/M/Y) it displays the day of the week as being one higher then it really is. 23 was a sunday. wich should make 24 monday. However it returns 2 both in %u and %w wich make it tuesday. I tried it on three different servers. one of them running 4.0.4pl1 and they all have the same problem. http://julia.o2.nl/problem.php (4.0.4) http://romeo.online.o2.nl/problem.php (4.1.2) Following is the code. I think I did everything right, according to the "it worked before" principle. 0 = zondag<br> 1 = maandag<br> 2 = dinsdag<br> 3 = woensdag<br> 4 = donderdag<br> 5 = vrijdag<br> 6 = zaterdag<br> 7 = zondag<br> <?php print(strftime("%u" , time()) . "<br>\n"); if(!ereg("([0-9]*)-([0-9]*)-([0-9]*) ([0-9]*):([0-9]*):([0-9]*)" , "2002-06-25 11:09:12" , $b)) Exit_Error("Invalid date format found"); // int mktime ( int hour, int minute, int second, int month, int day, int year [, int is_dst]) $timestamp = mktime($b[3] , $b[5] , $b[6] , $b[2] , $b[3] , $b[1]); print("dag " . $b[3] . "<br>\n"); print("maand " . $b[2] . "<br>\n"); print("jaar " . $b[1] . "<br>\n"); print("uur " . $b[4] . "<br>\n"); print("min " . $b[5] . "<br>\n"); print("sec " . $b[6] . "<br>\n"); print($timestamp . "<br>\n"); print(strftime("DAG 1 = maandag [%u] DAG 0 = zondag [%w]" , $timestamp) . "<br>\n"); print("------------------------<br>\n"); if(!ereg("([0-9]*)-([0-9]*)-([0-9]*) ([0-9]*):([0-9]*):([0-9]*)" , "2002-06-23 11:09:12" , $b)) Exit_Error("Invalid date format found"); // int mktime ( int hour, int minute, int second, int month, int day, int year [, int is_dst]) $timestamp = mktime($b[3] , $b[5] , $b[6] , $b[2] , $b[3] , $b[1]); print("dag " . $b[3] . "<br>\n"); print("maand " . $b[2] . "<br>\n"); print("jaar " . $b[1] . "<br>\n"); print("uur " . $b[4] . "<br>\n"); print("min " . $b[5] . "<br>\n"); print("sec " . $b[6] . "<br>\n"); print($timestamp . "<br>\n"); print(strftime("DAG 1 = maandag [%u] DAG 0 = zondag [%w]" , $timestamp) . "<br>\n"); print("------------------------<br>\n"); if(!ereg("([0-9]*)-([0-9]*)-([0-9]*) ([0-9]*):([0-9]*):([0-9]*)" , "2002-06-24 11:09:12" , $b)) Exit_Error("Invalid date format found"); // int mktime ( int hour, int minute, int second, int month, int day, int year [, int is_dst]) $timestamp = mktime($b[3] , $b[5] , $b[6] , $b[2] , $b[3] , $b[1]); print("dag " . $b[3] . "<br>\n"); print("maand " . $b[2] . "<br>\n"); print("jaar " . $b[1] . "<br>\n"); print("uur " . $b[4] . "<br>\n"); print("min " . $b[5] . "<br>\n"); print("sec " . $b[6] . "<br>\n"); print($timestamp . "<br>\n"); print(strftime("DAG 1 = maandag [%u] DAG 0 = zondag [%w]" , $timestamp) . "<br>\n"); ?> ~ ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=17965&edit=1

« previous php.bugs (#12290) next »