Solved

Date in dutch on any server windows or unix in php

Posted on 2013-01-25
5
261 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 109

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 109

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 109

Expert Comment

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

813 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

18 Experts available now in Live!

Get 1:1 Help Now