Jump to content

Date Converstion


Zharvek

Recommended Posts

Hello, I have a odd situation in PHP where I need to convert an date to a different format...

I have a date like, 2006-03-19 16:42:01 and I would like to "convert" it into something like...

$year = "2006";
$month = "03";
$day = "19";

I don't need the time at all. I just need the year, month, and day from that long string into some variables so I can pull data from the MySQL server correctly.

I was guessing that I could use a trim of some sort, but is this the best way?

I cannot change the long date format above because it is already in wide spread use on the site.

Thank you in advance to anyone who can help.
Link to comment
Share on other sites

[!--quoteo(post=356734:date=Mar 20 2006, 02:28 PM:name=Zharvek)--][div class=\'quotetop\']QUOTE(Zharvek @ Mar 20 2006, 02:28 PM) [snapback]356734[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Thank you very much, that solves a big part of the problem. Now that the time is removed, I can work on getting the parts into their variables correctly.
[/quote]

easiest way to do that that i know of is like so:
[code]
$date = "2006-03-20";
list($year, $month, $day) = explode("-", $date);
echo "$year<br />\n";
echo "$month<br />\n";
echo "$day<br />\n";
[/code]
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.