473,247 Members | 2,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,247 software developers and data experts.

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 42812
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

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

Similar topics

1
by: kris | last post by:
i want to get todays date in C++, unix environment. is the function getdate() will do that. can some one plese help me in this thanks
1
by: manning_news | last post by:
Using SQL 2000. I need to select rows based on a date range. Both the beginning date and ending date of the range will be entered in the mm/dd/yy format. There are 2 columns in the table called...
1
by: pnsreee | last post by:
Hi all I have date in mm/dd/yy format. to validate that one i am using cut and validating using if statements. But i want regexp. Please help me regarding this.
5
patjones
by: patjones | last post by:
Hi: I have a table that contains several date fields. I set the data type of those fields to Date/Time, and the format property (in table design view) to "mm/dd/yy". Likewise, in the form...
4
by: Ashraf Ansari | last post by:
Hi, How Can I convert MM/dd/yyyy format into dd/MM/yyyy and the date which is converted into dd/MM/yyyy should be in DateTime format. I do not want to store it as a string. Please help ...
3
by: sindhu | last post by:
Hello, i've a requirement where i want to change the entered date format based on the selection of whether mm/dd/yy , dd/mm/yy or yy/mm/dd Please give me some idea on how to do this using...
19
by: santanu mishra | last post by:
Hi , I am stuck with a requirement from my client to change the date format from mm/dd/yy to dd/mm/yy .If any body can help me out with this regard as its very much urgent. Regards,...
7
by: Bobby Edward | last post by:
What is the formatstring for mm/dd/yy (gridview column)? I always want it to be 6 digits. Thanks.
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.