Solved

Date in dutch on any server windows or unix in php

Posted on 2013-01-25
5
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 110

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 110

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 110

Expert Comment

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

739 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