PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 10th, 2000, 06:39 AM
ccm ccm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: Hong Kong
Posts: 73 ccm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 31 m 9 sec
Reputation Power: 14
Umm...I have no idea on how to store the date/time in MySQL database.

Anyone got a sample code which deal with time/date in PHP/MySQL?

Indeed, I am making a tiny guest book like program. I want to store/retreive time and date in/from MySQL database.


Reply With Quote
  #2  
Old March 10th, 2000, 07:39 AM
MartinD MartinD is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2000
Location: Bochum, NRW, Germany
Posts: 13 MartinD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
You need a special field in your table from the variable type DATETIME.
You can fill this with an extra MYSQL function named NOW() like this:

mysql_query("insert into table values (..., NOW(''),...");

The function NOW() insert the actual date/time, but you can even save every date/time by entering manually.

The data is stored in the format: YYYY-DD-MM HH:MM:SS

Check any MySQL tutorial for info.

Hope that will help you...

Martin

Reply With Quote
  #3  
Old March 10th, 2000, 12:04 PM
ccm ccm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: Hong Kong
Posts: 73 ccm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 31 m 9 sec
Reputation Power: 14
Thanks Martin.
now() works fine for me.
I just wonder if I can convert the format
of the date/time
i stored my date/time in the format of
YYYY-MM-DD HH:MM:SS

I want to show it in this format:
MM-DD-YYYY HH:MM in PHP

anyone know how to do it?

Reply With Quote
  #4  
Old March 10th, 2000, 12:41 PM
Kyuzo Kyuzo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 1999
Location: Annapolis, Maryland US
Posts: 113 Kyuzo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
select date_format(date_column, '%m %d %Y %l:%i %p) as When from table_name;

// %p gives AM/PM if you need it

Check out MySQL's date and time functions on the online manual for more formatting options (military time, ordinal suffixes, a bunch of stuff)

Reply With Quote
  #5  
Old March 10th, 2000, 08:54 PM
hkccm hkccm is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Location: Hong Kong
Posts: 24 hkccm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks Kyuzo. (This is 'ccm'. I am using another account in office.)
Indeed, I am a newbie in both PHP and MySQL.
I have already created a table with a column named 'date datetime'.
And I have used NOW() in PHP to store the date/time info in MySQL database.
For now, I retreive the date/time info by '$row->date' in PHP.
I have no idea what to do next.
Do I have to re-create the whole table?
And how do I implement the Date/Time format in my table?

Reply With Quote
  #6  
Old March 10th, 2000, 11:59 PM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan
Hi hkccm,

You don't have to recreate the table for changing a field type.

u may try this..

'alter table tblname change old_field new_field TIMESTAMP(-);'

for getting a special date format you can use
TIMESTAMP--with in bracket pass value for a specific format.

See the mysql documentation for the correct syntax.




Reply With Quote
  #7  
Old March 13th, 2000, 03:32 AM
MartinD MartinD is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2000
Location: Bochum, NRW, Germany
Posts: 13 MartinD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
To change the date/time format you can even use the regular expression stuff, it's quite mighty!

Example:
$date = "2000-03-13";
ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})",$date, $regs);
echo "$regs[3].$regs[2].$regs[1]";

Output: 13.03.2000

This function takes the date ($date) and splits it into an array ($regs) by odering after YYYY ($regs[1]), MM($regs[2]), DD($regs[3]) - there was a failure in my first posting ;-)).
You can now easily change the order by changing the order of the array.

Martin

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP/MySQL - storing date and time

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap