Solved

Date in dutch on any server windows or unix in php

Posted on 2013-01-25
5
257 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
ID: 38818570
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
ID: 38818720
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
ID: 38819092
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
ID: 38819841
super
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 38820121
Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

920 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

15 Experts available now in Live!

Get 1:1 Help Now