[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Php changing date format

Posted on 2011-10-07
5
Medium Priority
?
243 Views
Last Modified: 2012-05-12
Hi Experts,

I need to convert the date formatted like this:
Friday 28 October 2011
to
YYYY-MM-DD

Many Thanks
0
Comment
Question by:maccaj51
  • 3
5 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36931620
Date("Y-m-d") is probably what you want, or date('c')
0
 
LVL 4

Accepted Solution

by:
MattJellings earned 2000 total points
ID: 36931621
Hi,

This is a bit of a shot in the dark as I don't have access to test the code at the moment but you could try using the strtotime function that converts a string date/time into unix timestamp, then put this through date() to format it, something similar to:

echo date('Y-m-d', strtotime('Friday 28 October 2011'));

Open in new window


More info here:

strtotime - http://php.net/manual/en/function.strtotime.php
date - http://php.net/manual/en/function.date.php

Hope this helps,

Cheers

Matt
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36931647
This works.  You might want to use date_default_timezone_set() depending on where your clients and servers are located.

Best regards, ~Ray
<?php // RAY_temp_maccaj.php
error_reporting(E_ALL);


$in = 'Friday 28 October 2011';
echo date('Y-m-d', strtotime($in));

Open in new window

0
 

Author Closing Comment

by:maccaj51
ID: 36931682
Thanks Guys... Sorry Ray I just used the first one... Thank you for your response though
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month20 days, 7 hours left to enroll

867 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