0
votes

i want change name day in Indonesia language

Sunday -> Minggu - 0

Monday -> Senin - 1

Tuesday -> Selasa - 2

Wednesday -> Rabu - 3

Thursday -> Kamis - 4

Friday -> Jum'at - 5

Saturday -> Sabtu - 6

<?php 
date_default_timezone_set("Asia/Jakarta");
$date = date("Y-m-d");  // date now  - example :2016-02-07
$date_day_substr = substr($date, 9, 2);  // date day now - example : 7

$date_indonesia = date('w', $date_day_substr);

switch($date_indonesia){      
        case 0 : {
                    $date_indonesia ='Minggu'; //Sunday
                }break;
        case 1 : {
                    $date_indonesia ='Senin'; // Monday
                }break;
        case 2 : {
                    $date_indonesia ='Selasa'; //Tuesday
                }break;
        case 3 : {
                    $date_indonesia ='Rabu'; //Wednesday
                }break;
        case 4 : {
                    $date_indonesia ='Kamis'; //Thursday
                }break;
        case 5 : {
                    $date_indonesia ="Jum'at"; //Friday
                }break;
        case 6 : {
                    $date_indonesia ='Sabtu';  //Saturday
                }break;
        default: {
                    $date_indonesia ='UnKnown';
                }break;
    }

echo $date_indonesia;  //this result day : Wednesday -> Rabu - 3
//this wrong, cause now  day : Monday -> Minggu - 0
?>

Help me Thank's

2

2 Answers

2
votes

You need to provide a UNIX timestamp for the second parameter of the date function. You are providing 7 in the second parameter in the which means 7 second after Jan 1, 1970 00:00:00 UTC. And that day was thursday. So your code result in displaying Kamis i.e. Thursday.

You can simply use this code to get today's day.

$date_indonesia = date('w');

And for another date, try

$date_indonesia = dat('w',strtotime("DD-MM-YYYY");

where DD-MM-YYYY represents that date.

0
votes

I tested this code works perfect. Let me know if need something more.

<?php 
date_default_timezone_set("Asia/Jakarta");
$date_indonesia = date('w');

switch($date_indonesia){      
        case 0 : {
                    $date_indonesia ='Minggu'; //Sunday
                }break;
        case 1 : {
                    $date_indonesia ='Senin'; // Monday
                }break;
        case 2 : {
                    $date_indonesia ='Selasa'; //Tuesday
                }break;
        case 3 : {
                    $date_indonesia ='Rabu'; //Wednesday
                }break;
        case 4 : {
                    $date_indonesia ='Kamis'; //Thursday
                }break;
        case 5 : {
                    $date_indonesia ="Jum'at"; //Friday
                }break;
        case 6 : {
                    $date_indonesia ='Sabtu';  //Saturday
                }break;
        default: {
                    $date_indonesia ='UnKnown';
                }break;
    }

echo $date_indonesia; 
?>