Translating MySQL timestamp to datetime

This is a discussion on Translating MySQL timestamp to datetime within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi All, Any thoughts on the easiest way to translate a MySQL timestamp (which looks like 20040422090941) to the datetime ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-22-2004
Joshua Beall
 
Posts: n/a
Default Translating MySQL timestamp to datetime

Hi All,

Any thoughts on the easiest way to translate a MySQL timestamp (which looks
like 20040422090941) to the datetime format (which looks like 2004-04-22
09:09:41). This is just to make it easier for a human to read it.

I have thought about splitting it into chunks using something like
str_split, then piecing it back together, but it seems like there should be
an easier way. And also, I am not running PHP5.

I already tried date("Y-m-d H:i:s",strtotime("20040422090941")), and had no
luck. strtotime cannot handle that format.

This seems like the sort of thing you should be able to do in 1 line of
code. Any pointers?

-Josh


Reply With Quote
  #2 (permalink)  
Old 04-22-2004
DB McGee
 
Posts: n/a
Default Re: Translating MySQL timestamp to datetime

Joshua Beall wrote:
> Hi All,
>
> Any thoughts on the easiest way to translate a MySQL timestamp (which looks
> like 20040422090941) to the datetime format (which looks like 2004-04-22
> 09:09:41). This is just to make it easier for a human to read it.
>
> I have thought about splitting it into chunks using something like
> str_split, then piecing it back together, but it seems like there should be
> an easier way. And also, I am not running PHP5.
>
> I already tried date("Y-m-d H:i:s",strtotime("20040422090941")), and had no
> luck. strtotime cannot handle that format.
>
> This seems like the sort of thing you should be able to do in 1 line of
> code. Any pointers?
>
> -Josh


Select the date value from MySQL as a Unix timestamp eg.

SELECT UNIX_TIMESTAMP(date) as date FROM table

Then you can use the date() function on it with no problems.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:05 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0