Date in dutch on any server windows or unix in php

Hi

Yes I have been on php.net on every other site and only ended up with code that did work on a windows system but not on any of my servers, and vice versa.

I want the following date in dutch:

Friday 25 January 2013 22:05

it should display:

Vrijdag 25 Januari 2013  2013 22:05

I  have tried every setlocale too, but have not found any that worked on every site.

Please dont send the link to php.net I have been there and i could not get it to work
PeterdeBAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Ray PaseurConnect With a Mentor Commented:
I was looking at it this way.  I think a combination of the two or something like str_replace() using arrays would do the job.

<?php // dutch_date.php
error_reporting(E_ALL);

function dutch_date($pattern='c', $timestamp=NULL)
{
    // SAVE THE TIMEZONE
    $tz = @date_default_timezone_get();
    date_default_timezone_set('Europe/Amsterdam');
    
    // GET THE ENGLISH DATE
    if (!$timestamp)
    {
        $english_date = date($pattern);
    }
    else
    {
        $english_date = date($pattern, $timestamp);
    }
    
    // TRANSLATE TO DUTCH
    $weekdays = array
    ( 'Monday'    => 'maandag'
    , 'Tuesday'   => 'dinsdag'
    , 'Wednesday' => 'woensdag'
    , 'Thursday'  => 'donderdag'
    , 'Friday'    => 'vrijdag'
    , 'Saturday'  => 'zaterdag'
    , 'Sunday'    => 'zondag'
    )
    ;
    $months = array
    ( 'January'   => 'januari'
    , 'February'  => 'februari'
    , 'March'     => 'maart'
    , 'April'     => 'april'
    , 'May'       => 'mei'
    , 'June'      => 'juni'
    , 'July'      => 'juli'
    , 'August'    => 'augustus'
    , 'September' => 'september'
    , 'October'   => 'oktober'
    , 'November'  => 'november'
    , 'December'  => 'december'
    )
    ;
    $dutch_date = $english_date;
    foreach ($weekdays as $e => $d) $dutch_date = str_replace($e, $d, $dutch_date);
    foreach ($months   as $e => $d) $dutch_date = str_replace($e, $d, $dutch_date);
    
    date_default_timezone_set($tz);
    
    return $dutch_date;
}

echo dutch_date('l, j F, Y');

Open in new window

Best regards, ~Ray
0
 
Ray PaseurCommented:
I think you can set up your own translation table.  You would then use the PHP date() function to format the date in English and make a str_replace() to translate to Dutch.  If you will tell me the names of the weekdays and months, I will show you how to code it. ~Ray
0
 
PeterdeBAuthor Commented:
hey thx for your fast response

function nlDate($parameters){

// AM of PM doen we niet aan
$parameters = str_replace("A", "", $parameters);
$parameters = str_replace("a", "", $parameters);

$datum = date($parameters);

// Vervang de maand, klein
$datum = str_replace("january", "januari", $datum);
$datum = str_replace("february", "februari", $datum);
$datum = str_replace("march", "maart", $datum);
$datum = str_replace("april", "april", $datum);
$datum = str_replace("may", "mei", $datum);
$datum = str_replace("june", "juni", $datum);
$datum = str_replace("july", "juli", $datum);
$datum = str_replace("august", "augustus", $datum);
$datum = str_replace("september", "september", $datum);
$datum = str_replace("october", "oktober", $datum);
$datum = str_replace("november", "november", $datum);
$datum = str_replace("december", "december", $datum);

// Vervang de maand, hoofdletters
$datum = str_replace("January", "Januari", $datum);
$datum = str_replace("February", "Februari", $datum);
$datum = str_replace("March", "Maart", $datum);
$datum = str_replace("April", "April", $datum);
$datum = str_replace("May", "Mei", $datum);
$datum = str_replace("June", "Juni", $datum);
$datum = str_replace("July", "Juli", $datum);
$datum = str_replace("August", "Augustus", $datum);
$datum = str_replace("September", "September", $datum);
$datum = str_replace("October", "Oktober", $datum);
$datum = str_replace("November", "November", $datum);
$datum = str_replace("December", "December", $datum);

// Vervang de maand, kort
$datum = str_replace("Jan", "Jan", $datum);
$datum = str_replace("Feb", "Feb", $datum);
$datum = str_replace("Mar", "Maa", $datum);
$datum = str_replace("Apr", "Apr", $datum);
$datum = str_replace("May", "Mei", $datum);
$datum = str_replace("Jun", "Jun", $datum);
$datum = str_replace("Jul", "Jul", $datum);
$datum = str_replace("Aug", "Aug", $datum);
$datum = str_replace("Sep", "Sep", $datum);
$datum = str_replace("Oct", "Ok", $datum);
$datum = str_replace("Nov", "Nov", $datum);
$datum = str_replace("Dec", "Dec", $datum);

// Vervang de dag, klein
$datum = str_replace("monday", "maandag", $datum);
$datum = str_replace("tuesday", "dinsdag", $datum);
$datum = str_replace("wednesday", "woensdag", $datum);
$datum = str_replace("thursday", "donderdag", $datum);
$datum = str_replace("friday", "vrijdag", $datum);
$datum = str_replace("saturday", "zaterdag", $datum);
$datum = str_replace("sunday", "zondag", $datum);

// Vervang de dag, hoofdletters
$datum = str_replace("Monday", "Maandag", $datum);
$datum = str_replace("Tuesday", "Dinsdag", $datum);
$datum = str_replace("Wednesday", "Woensdag", $datum);
$datum = str_replace("Thursday", "Donderdag", $datum);
$datum = str_replace("Friday", "Vrijdag", $datum);
$datum = str_replace("Saturday", "Zaterdag", $datum);
$datum = str_replace("Sunday", "Zondag", $datum);

// Vervang de verkorting van de dag, hoofdletters
$datum = str_replace("Mon", "Maa", $datum);
$datum = str_replace("Tue", "Din", $datum);
$datum = str_replace("Wed", "Woe", $datum);
$datum = str_replace("Thu", "Don", $datum);
$datum = str_replace("Fri", "Vri", $datum);
$datum = str_replace("Sat", "Zat", $datum);
$datum = str_replace("Sun", "Zon", $datum);

return $datum;

}

Open in new window


I had been busy with writing this, and then stumbled across this function
0
 
PeterdeBAuthor Commented:
super
0
 
Ray PaseurCommented:
Thanks for the points and thanks for using EE, ~Ray
0
All Courses

From novice to tech pro — start learning today.