Current location: Hot Scripts Forums » Programming Languages » PHP » date format


date format

Reply
  #1 (permalink)  
Old 12-16-03, 11:30 AM
tcooper tcooper is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
date format

I have a form in PHP. There is a textbox where the user enters a project start date (mm/dd/yyyy). I need to then import this date into mysql but don't know how to convert it to the proper format (yyyy/mm/dd). Can you please help?
Reply With Quote
  #2 (permalink)  
Old 12-16-03, 11:35 AM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
Do this.

time();

Insert that value into the db, then date("FORMAT", $Fetch_Timestamp_From_Mysql); and it will turn it into a user friendly date.
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Reply With Quote
  #3 (permalink)  
Old 12-16-03, 05:59 PM
korn korn is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Acecool
Do this.

time();

Insert that value into the db, then date("FORMAT", $Fetch_Timestamp_From_Mysql); and it will turn it into a user friendly date.
does there a function exist for doing the opposit?(turning 19/11/2003 back to timestamp...)

thx m8te
Reply With Quote
  #4 (permalink)  
Old 12-16-03, 09:26 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

Quote:
Originally Posted by korn
does there a function exist for doing the opposit?(turning 19/11/2003 back to timestamp...)

thx m8te
If you need to convert your date string into UNIX timestamp, check these out:

mktime()
http://www.php.net/manual/en/function.mktime.php

strtotime()
http://www.php.net/manual/en/function.strtotime.php

Hope this helps.
__________________
Blavv =|
Reply With Quote
  #5 (permalink)  
Old 12-18-03, 07:48 AM
pshylocke pshylocke is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by tcooper
I have a form in PHP. There is a textbox where the user enters a project start date (mm/dd/yyyy). I need to then import this date into mysql but don't know how to convert it to the proper format (yyyy/mm/dd). Can you please help?
I may be over simplifying but couldn't you just put 3 fields in the form for a date (I see many sites do this).

Code:
<input type="text" name="month" size="2">
<input type="text" name="day" size="2">
<input type="text" name="year" size="4">
It should look fine then you could just do:

Code:
$tstamp = $year . -$month . -$day
The dash isn't necessary but gives a nice touch if you printf/view $tstamp.
Reply With Quote
  #6 (permalink)  
Old 12-18-03, 11:58 AM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Good morning. What a nice day today (in Vancouver)!

Anyways, in reply to pshylocke, I totally agree with your suggestion - the simpler, the better, and the simplest, the best.

But if the user input in this case is like "yyyy/mm/dd" or "dd/mm/yyyy", then you have to chop this string into threee parts. Besides, the last question was asking the way to convert this into unix timestamp, if I was not mistaken. So mktime() or strtotime() in conjunction with substr(), I thought, was a good idea.

Good day.
__________________
Blavv =|
Reply With Quote
  #7 (permalink)  
Old 12-18-03, 12:24 PM
pshylocke pshylocke is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by blaw
Good morning. What a nice day today (in Vancouver)!

Anyways, in reply to pshylocke, I totally agree with your suggestion - the simpler, the better, and the simplest, the best.

But if the user input in this case is like "yyyy/mm/dd" or "dd/mm/yyyy", then you have to chop this string into threee parts. Besides, the last question was asking the way to convert this into unix timestamp, if I was not mistaken. So mktime() or strtotime() in conjunction with substr(), I thought, was a good idea.

Good day.
I see what your sayin Blaw. Just gettin my feet wet
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Date From Access 2000 Database Kaikki ASP 4 09-25-03 06:04 PM
date reformatting... dsumpter PHP 1 09-23-03 01:05 AM
date format for mysql runya PHP 3 07-28-03 12:56 AM
Date format alanrenouf PHP 2 07-17-03 04:28 AM
Days left to certain date. Data from MySQL alfreds PHP 4 06-17-03 09:26 AM


All times are GMT -5. The time now is 07:34 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.