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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...