Jump to content

Reformat date


proctk

Recommended Posts

try

 

<?php

// Date
$touchoftechDate = "2008-03-05";

// Split String into an Array
$array = explode("-",$touchoftechDate);

// Implode the array into a String in the correct order
$touchoftechDate = implode("-",array($array[2],$array[1],$array[0]));

// strtotime will convert the string to a timestamp, date() will convert the timestamp to a formmated date.
$date = date("l, F m Y",strtotime($touchoftechDate));

// echo the result
echo($date);

?>

 

Dates MUST be in format: YYYY-MM-DD

 

you could also wrap this into a function

 

 

hope this helps,

Link to comment
Share on other sites

Because the "m" in the date() function format string means month. "d" or "j" would be needed to give the day number. Using (or debugging) any code involves making use of the programming language manual. uniflare just gave a quick example of how you could do this and it was likely untested, like most of the quick code examples that are posted in a forum. When it did not work, you could have used the manual to find out why and make it work yourself.

 

In fact all the code to explode and implode the date is unnecessary because strtotime() works on a yyyy-mm-dd format.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.