Hello,
I need to convert string format "18 novembre 2012" (month is wrtite in italian) to php date.
Can you help me?

Recommended Answers

All 4 Replies

Member Avatar for LastMitch

@giovannitao

I need to convert string format "18 novembre 2012" (month is wrtite in italian) to php date.

I don't understand what you are trying to do?

You can't used date() function to do that.

You have to used strftime () function.

You can read more about it here:

http://us2.php.net/manual/en/function.strftime.php

You just want convert "18 novembre 2012" in Italian.

Try this:

<?php
//Questo è il modo di impostare l'ora locale in lingua italiana
setlocale(LC_TIME, 'it_IT');
//Questo eco la data: 18 novembre 2012 in italiano
echo strftime("%d %B %Y");
?>
Member Avatar for diafol

I think he needs to go the other way

18 novembre 2012 -> something else like 2012-11-18 or 18/11/2012

strtotime only works with English text. You could write your own function - pretty easy:

function toDate($date){
    list($day,$textmonth,$year) = explode(" ",$date);
    //if day in single digits:
    // $day = str_pad($day,2,'0',STR_PAD_LEFT);

    $m = array('gennaio'=>'01','febbraio'=>'02'...);
    $month = $m[$textmonth];
    //either this is enough:
    return $day . '/' . $month . '/' .$year;

    //or you can make a unixtimestamp with these and create any format you want
}

Locales are fine on UNix, Just try using them on Windows and you'll get an elephant-sized headache. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.