Reply
How to convert 1-7(day) 1-31(date) 1-12(month) and 2007 info the equiv of date('r')
Old 08-20-2007, 10:50 AM How to convert 1-7(day) 1-31(date) 1-12(month) and 2007 info the equiv of date('r')
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,284
Name: Dan
Location: Swindon
hey,

i have a script which i have the user choose a date via dropdowns and end up with 4 fields in my DB
with
Day
date
month
year

but down i im at the point where i want to have the events which i retrieve from the DB to be sorted by date, from the newest to the oldest.

and while i like the format it displays of


Sunday 1/1/2007

its all done like:
PHP Code:
$content .= $row['day'];
$content .= ' ';
$content .= $row['date'];
$content .= '/';
$content .= $row['month'];
$content .= '/';
$content .= $row['year']; 
so how would i go about having the script order it by date??

also how could i validate that the input is a valid date?

so if they input

Sunday 25 / 02 / 2007

and it happens that the 25th of feb 2007 is actually a monday

or they enter something like 30/02/2007 which obviously isnt right...

Thanks
TAlkupation for people who help.
Dan
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
When You Register, These Ads Go Away!
Old 08-20-2007, 11:08 AM Re: How to convert 1-7(day) 1-31(date) 1-12(month) and 2007 info the equiv of date('
Ultra Talker

Posts: 482
Honestly? It comes down to the fact that you really shouldn't be using 4 fields in the DB. Why aren't you just storing the given date in a single datetime (or even timestamp) type column? That way you can sort on the column when you make the SQL request and then just format the date however you want when displaying it to the user...
__________________
Free PHP Obfuscator
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 08-20-2007, 11:51 AM Re: How to convert 1-7(day) 1-31(date) 1-12(month) and 2007 info the equiv of date('
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,284
Name: Dan
Location: Swindon
i know,

the only reason is becasue i dont know how to convert it to what i want

i would prefer to save it as date('r') but wouldnt know how to go aboutsaving it in that format. from four drop down boxes.

how could i convertit into the date('r') format?...
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 08-20-2007, 02:55 PM Re: How to convert 1-7(day) 1-31(date) 1-12(month) and 2007 info the equiv of date('
Super Talker

Posts: 118
retrieving a date and formatting it from a DB is so much easier.

http://dev.mysql.com/doc/refman/5.0/...functions.html

Let's say you have a timestamp field and you want to display it as: Sunday 25/4/2007

SELECT DATE_FORMAT(datefield, '%W %e/%c/%Y')
__________________
flann
Free mortgage calculator
flann is offline
Reply With Quote
View Public Profile
 
Old 08-20-2007, 02:59 PM Re: How to convert 1-7(day) 1-31(date) 1-12(month) and 2007 info the equiv of date('
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,284
Name: Dan
Location: Swindon
Ok yea... but how do i get that timestamp from the four drop downs i have!!?
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 08-20-2007, 03:02 PM Re: How to convert 1-7(day) 1-31(date) 1-12(month) and 2007 info the equiv of date('
Super Talker

Posts: 118
when you are inserting the values into the database, just simply put them together as a date, and you don't need to worry about the day of the week ie. Sunday because MySQL will be able to figure that out for you.
__________________
flann
Free mortgage calculator
flann is offline
Reply With Quote
View Public Profile
 
Old 08-20-2007, 04:08 PM Re: How to convert 1-7(day) 1-31(date) 1-12(month) and 2007 info the equiv of date('
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,284
Name: Dan
Location: Swindon
ok so what format should i save them in?

like 01 03 07 or 01/03/07 ?.. :s
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 08-20-2007, 04:21 PM Re: How to convert 1-7(day) 1-31(date) 1-12(month) and 2007 info the equiv of date('
Super Talker

Posts: 118
yyyy-mm-dd
__________________
flann
Free mortgage calculator
flann is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to convert 1-7(day) 1-31(date) 1-12(month) and 2007 info the equiv of date('r')
 

Thread Tools

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14334 seconds with 12 queries