regoch Posted May 23, 2011 Share Posted May 23, 2011 <?php $dayNames = array("Nedelja", "Ponedeljak", "Utorak", "Srijeda", "Četvrtak", "Petak", "Subota"); $dan = $dayNames[date('N')]; echo $dan.", ".date('d.m.Y.') ; ?> This is my code for showing days in my language, but it works on every day except sunday! Does anybody have any clue? Thanks! Link to comment https://forums.phpfreaks.com/topic/237271-date-problem/ Share on other sites More sharing options...
btherl Posted May 23, 2011 Share Posted May 23, 2011 Arrays are indexed from 0 by default, making your array indexed from 0 - 6, but date('N') returns a number in the range 1-7. <?php $dayNames = array("Nedelja", "Ponedeljak", "Utorak", "Srijeda", "Četvrtak", "Petak", "Subota"); $dan = $dayNames[date('N')-1]; # <-- Subtract 1 from the result of date('N') echo $dan.", ".date('d.m.Y.') ; ?> Edit: Sorry, you may need to re-order your array to make that work. The "Subota" will need to go to the start, everything else would be in the same position. Link to comment https://forums.phpfreaks.com/topic/237271-date-problem/#findComment-1219305 Share on other sites More sharing options...
Pikachu2000 Posted May 23, 2011 Share Posted May 23, 2011 From the PHP manual entry for date: N ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0) 1 (for Monday) through 7 (for Sunday) But your array indices start at 0. Start them at 1, and re-order them like this: $dayNames = array( 1 => "Ponedeljak", "Utorak", "Srijeda", "Četvrtak", "Petak", "Subota", "Nedelja" ); Link to comment https://forums.phpfreaks.com/topic/237271-date-problem/#findComment-1219306 Share on other sites More sharing options...
regoch Posted May 24, 2011 Author Share Posted May 24, 2011 Thanks, now I wait for sunday to see if it's works! Link to comment https://forums.phpfreaks.com/topic/237271-date-problem/#findComment-1219469 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.