5

I want to transform a date from this format: 01/07/09 to this jan 07,09.

How can I do that in PHP?

3 Answers 3

8

I'm pretty sure this is what you need.

<?php echo date('M d, y', strtotime('01/07/09'));?>
Sign up to request clarification or add additional context in comments.

Comments

6

Use strptime to parse the value you've got, then date to output it in the format you want:

echo date("M d,y", strptime("01/07/09", "d/m/y"));

If you're on Windows, or using a version of PHP where strptime is not available (< PHP 5.1.0), then use strtotime instead, but be careful to make sure your date is in a US English format (i.e. "01/07/09" means January 7th 2009, not 1st July 2009).

Also, if you really want jan, rather than Jan, then use strtolower:

echo strtolower(date("M d,y", strptime("01/07/09", "d/m/y"));

3 Comments

Also note, strptime is not implemented on Windows.
@Brian, thanks - edited in a comment about using strtotime where strptime is unavailable.
you have the order of arguments for date mixed up. Should be: date( $format, [ $timestamp ] )
2

Just pass the date variable to strtotime. See PHP manual for more.

$date = "01/07/09";
echo date("M d,y", strtotime($date));   

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.