Hopefully you are storing your dates in a DateTime column. If you are, and you are not "Messing" around with the values when you return them, then they should still be DateTime data in ASP. Specifically.... in ASP.... they should be a DATE date type. (The Date data type has both date and time).
One of the developers that works for me was having a similar problem today. My advice to him was.... when dealing with date and time, keep the data in a Date data type as much as possible. Believe it or not, the folks that wrote ASP spent a lot of time and energy making sure that Date operations work properly. Once you start messing around with strings... all bets are off.
well my database has these back to front thats why
You should understand a little about how dates are stored. I'm assuming you are using a SQL Server database. In SQL Server, dates are stored as a pair of integers.
When you say that the database has them back to front, that's not really true. When you select a date from the database, your application recognizes that it's a date, and then it chooses to display them a certain way. For example, SQL Server Management Studio (and Query Analyzer) will display dates like this:
2009-06-03 19:07:23.763
But... you need to realize that this is just a display of the actual data, not the data itself. Nobody would be able to make sense of dates if SQL Server displayed them as a pair of integers.
Anyway... my point is. Treat your dates as though they are dates, and you shouldn't have too many problems. If you have a string (that represents a date) that you want to treat as a date, then you should use the cDate function. Like this:
pEndDate = cdate("6/7/2009 21:15:58")
Even better is use the DateSerial And TimeSerial functions (if you can). Example:
pEndDate = DateSerial(2009,6,7) + TimeSerial(21,15,58)
If you are retrieving date data from a database, then you should use the cDate function. Ex:
pEndDate = cDate(RS("MyDateColumn"))
In ASP, all variables are actually variants (they can take on any data type). But... variants have sub types too. So.... if your variable is a string, then string handling functions apply. If the sub-type of the variable is a date, then date handling applies.
For example, if you do this...
Code:
MyDate = "6/4/2009 13:15:58"
Response.Write MyDate + 1
You will get an error because you are trying to add 1 to string. But, if you do this....
Code:
MyDate = cDate("6/4/2009 13:15:58")
Response.Write MyDate + 1
You will get an output like this: "6/5/2009 13:15:58"
The cDate function set the variables sub-type to Date. Adding 1 to a date adds a day (so you get June 5 instead of the original June 4).
These are very important concepts to understand. Please make sure all of this makes sense to you. If it doesn't, please feel free to ask followup questions.
-George
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom