Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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, 09: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
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
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
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 08-20-2007, 10: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: 483
Trades: 0
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...
__________________

Please login or register to view this content. Registration is FREE
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 08-20-2007, 10: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
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
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?...
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 08-20-2007, 01: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: 130
Trades: 0
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

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
flann is offline
Reply With Quote
View Public Profile
 
Old 08-20-2007, 01: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
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Ok yea... but how do i get that timestamp from the four drop downs i have!!?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 08-20-2007, 02: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: 130
Trades: 0
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

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
flann is offline
Reply With Quote
View Public Profile
 
Old 08-20-2007, 03: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
Defies a Status

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

like 01 03 07 or 01/03/07 ?.. :s
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 08-20-2007, 03: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: 130
Trades: 0
yyyy-mm-dd
__________________
flann

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
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 Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





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



Page generated in 0.74047 seconds with 12 queries