469,281 Members | 2,484 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,281 developers. It's quick & easy.

How to convert timestamp into mm:dd:yy format.

kamill
71
I have a timestamp type field into my mysql database table. Now threw php i need to change it into mm:dd:yy formate.Threw witch function i can do it. Please help me with an examole. suppose timestamp is this 20070209162211 then how can i convert it into mm:dd:yy formate.
...........
kamill
Feb 9 '07 #1
11 42333
date( "d/m/Y", $unix_timestamp);

but 20070209162211 it isn't unix timestamp.
unix timestamp is a number of seconds from 1970 year
Feb 9 '07 #2
20070209162211 is
2007-02-09 16:22:11

it's more simple to convert. split this string by symbols using substr() and its all
Feb 9 '07 #3
devsusen
136 100+
unix timestamp and value stored in mysql timestamp datatype are different. There is no such function which can convert mysql timestamp value to mm:dd:yy format.

So its better to use sustr() to get year, month, date, hour, minute, seconds then you can use it. the format for mysql timestamp type is YYYYMMDDhhmmss.

susen
Feb 9 '07 #4
unix timestamp and value stored in mysql timestamp datatype are different. There is no such function which can convert mysql timestamp value to mm:dd:yy format.
susen
you are wrong
there is a date() function to convert timestamp to every date format
http://www.php.net/date
Feb 9 '07 #5
sunbin
7
hi,

i have used this code block many times,

Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3. $time_stamp=time(); //gives timestamp
  4. $date_format=date("m:d:y",$time_stamp); // formats timestamp in mm:dd:yy 
  5.  
  6. print $date_format; // results here ... 02 : 11 : 07
  7.  
  8. ?>
Solved ???

Sunbin
Feb 11 '07 #6
devsusen
136 100+
you are wrong
there is a date() function to convert timestamp to every date format
http://www.php.net/date
date() can accept timestamp parameter if it is only unix timestamp not the value stored in mysql table as timestamp datatype.

Susen
Feb 13 '07 #7
ronverdonk
4,258 Expert 4TB
I cannot follow if you had your reply, so I'll throw this one in to convert your YYYYMMDDHHMMSS into MM: DD:YY:

Expand|Select|Wrap|Line Numbers
  1. echo sprintf("%02s:%02s:%02s", substr($date,4,2),substr($date,6,2),substr($date,2,2));
Ronald :cool:
Feb 13 '07 #8
devsusen
136 100+
I cannot follow if you had your reply, so I'll throw this one in to convert your YYYYMMDDHHMMSS into MM: DD:YY:

Expand|Select|Wrap|Line Numbers
  1. echo sprintf("%02s:%02s:%02s", substr($date,4,2),substr($date,6,2),substr($date,2,2));
Ronald :cool:
I accept this as a good solution.

Susen
Feb 14 '07 #9
ronverdonk
4,258 Expert 4TB
I accept this as a good solution.

Susen
I am so glad you do!

Ronald :cool:
Feb 14 '07 #10
ronlg
1
I just learned how to do this properly...
What you want to do is have it all handled in your MySQL Query...


In my case, which might not work for you, I have:

Expand|Select|Wrap|Line Numbers
  1. $select = array();
  2. $select[] = "MONTH(timeStamp) AS theMonth";
  3. $select[] = "DAY(timeStamp) AS theDay";
  4.  
That's just part of my query...

Later, when I want to echo the results, I use:

Expand|Select|Wrap|Line Numbers
  1. <?=$results["theMonth"]."/".$results["theDay"];?>
  2.  
Hopefully this helps. One of our dev. guys just showed it to me and it works like a charm!
Aug 19 '08 #11
are these examples pulling the timestamp from a database row, and displaying in a new format?
Oct 8 '10 #12

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by manning_news | last post: by
1 post views Thread by pnsreee | last post: by
4 posts views Thread by Ashraf Ansari | last post: by
3 posts views Thread by sindhu | last post: by
7 posts views Thread by Bobby Edward | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.