PDA

View Full Version : Date as one field or three?


murgeltd
06-01-2006, 05:17 PM
Not sure if this is the right section (I am coding in asp) so forgive me if it's not.

In the past I have stored dates in a database as one field in a record. I have recently viewed some developers code that separates the day, month, year as three different fields in a database of 2 numbers only.

That's all well and good, but I am trying to create a latest news page that will only display the three latest item in the news table, based on posted date.

I can visually work out how I code to check for the three latest records based on one date field, but is there an easy way to concatinate three fields into one date variable and their do a condition on that??

Any comments on best practise for dates is much appreciated.

Regards,

Andy

BarrMan
06-01-2006, 05:34 PM
You can simply make it in sql statement:
rs.open "SELECT * FROM news ORDER BY DATE DESC",con
This will view the latest news first.
Now to display them you can:
For i=1 to 3
response.write(rs("news_title"))
rs.movenext
Next

Hope that helped.

murgeltd
06-01-2006, 05:56 PM
Thanks for the coding help.

I guess your answer then would be to use just the one field for any date required, and not three fields containing day, month, year?

Thanks again for the code help.

Andy

BarrMan
06-01-2006, 06:16 PM
Oh, One field will be the best.
you can have it by the command: now()

degsy
06-06-2006, 02:50 PM
e.g.
date_split
Fields: id, title, m, d, y

1, test, 6, 6, 6


SELECT *, Cdate([d] & "/" & [m] & "/" & [y]) as theDate, Format(Cdate([d] & "/" & [m] & "/" & [y]),'Long Date') as FormattedDate
FROM date_split
WHERE Cdate([d] & "/" & [m] & "/" & [y]) >= Now()



theDate FormattedDate id title d m y
07/06/2006 07 June 2006 4 test3 7 6 6