Solved

Date in dutch on any server windows or unix in php

Posted on 2013-01-25
5
253 Views
Last Modified: 2013-01-25
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
0
Comment
Question by:PeterdeB
  • 3
  • 2
5 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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
 

Author Comment

by:PeterdeB
Comment Utility
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
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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
 

Author Closing Comment

by:PeterdeB
Comment Utility
super
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn how to count occurrences of each item in an array.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now