php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17965 Strftime returns day of the week 1 to high after 23-6-2002
Submitted: 2002-06-25 05:57 UTC Modified: 2002-06-27 21:14 UTC
From: didier dot peereboomvoller at o2 dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.1.2 OS: Linux 2.4.??
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: didier dot peereboomvoller at o2 dot com
New email:
PHP Version: OS:

 

 [2002-06-25 05:57 UTC] didier dot peereboomvoller at o2 dot 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");
?>
~                                                                                                                                                                                                            

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-26 09:42 UTC] didier dot peereboomvoller at o2 dot com
It maybe that the error lies in mktime instead.
 [2002-06-26 15:06 UTC] 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-27 03:51 UTC] didier dot peereboomvoller at o2 dot 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-27 04:01 UTC] 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 21:14 UTC] sniper@php.net
$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)


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 14:01:27 2025 UTC