Skip to content
Advertisement

Date and time in Greek

I’m currently using a website to get the time in Athens:

$d = new DateTime("now", new DateTimeZone("Europe/Athens"));
echo $d->format("l, d M Y");

But I would like the date to be displayed in Greek and in the same format.

Advertisement

Answer

I was in the quest to find the same thing but I didn’t find a full solution as I needed it. In my case I need to write the posted datetime of the article in Greek like Αναρτήθηκε Σάββατο 2 Μαΐου 2015.

So using some code of costastg answer, I managed to put together the following function.

I am sure there are other solutions out there:

function formatToGreekDate($date){
    //Expected date format yyyy-mm-dd hh:MM:ss
    $greekMonths = array('Ιανουαρίου','Φεβρουαρίου','Μαρτίου','Απριλίου','Μαΐου','Ιουνίου','Ιουλίου','Αυγούστου','Σεπτεμβρίου','Οκτωβρίου','Νοεμβρίου','Δεκεμβρίου');
    $greekdays = array('Δευτέρα','Τρίτη','Τετάρτη','Πέμπτη','Παρασκευή','Σάββατο','Κυριακή');

    $time = strtotime($date);
    $newformat = date('Y-m-d',$time);

    return $greekdays[date('N', strtotime($newformat))-1].' '. date('j', strtotime($newformat)).' '.$greekMonths[date('m', strtotime($newformat))-1]. ' '. date('Y', strtotime($newformat)); // . ' '. $date;
}

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement