Jump to content

Translating date


Recommended Posts

Hi! I have one issue with date translating. Here is my code: <?php $day = date("l"); $daynum = date("j"); $month = date("M"); $year = date("Y"); if($day == "Monday"){ $day = "Ponedjeljak"; }elseif($day == "Tuesday"){ $day = "Utorak"; } /* etc, translating day */ if($month == "January"){ $month = "siječnja"; }elseif($month == "February"){ $month = "veljače"; } /* etc, translating month */ elseif($month == "December"){ $month = "prosinca"; } echo $day . ", " . $daynum . ". " . $month . " " . $year . "."; ?> Now, problem is: Why output is "Utorak, 11. Dec 2012." (there should be "Utorak, 11. prosinca 2012.")? It translated only day, but not month, although code for month is similar to code for day.

Link to comment
Share on other sites

in the documentation, it will show you what value you will be getting back from this line

$month = date("M");


M A short textual representation of a month, three letters JAN through DEC
so as in the previous post, you should be checking against the short representation. also, you might want to consider an array to do the mappings, so you don't have super long if/else conditionals, i.e.
$dayMapper =  array(  'Monday'  => 'Ponedjeljak','Tuesday'   => 'Utorak'); echo 'today is => ' + $dayMapper[date('l')]);

Edited by thescientist
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...