very annoying DATES

This is a discussion on "very annoying DATES" within the Classic ASP section. This forum, and the thread "very annoying DATES are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old May 13th, 2005, 16:29
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
very annoying DATES

i have two date and time problems!!

on this simple forum i have written, i have it storing the lastupdated date in a field, and ordering the results when i pull them from the database by lastupdated DESC - this should produce the desired result of latest changed at the top, right?! well it did, until today - any posts added on the 13/05/2005 are chucked after stuff on the 10-12th 2005 - which i do not understand. all dates are in the same format.....

and how can i get dates to go in English time? at the moment, i have session.LCID or whatever it is set to english, but occasionally, the date gets printed in american... how can i solve that?

  #2 (permalink)  
Old May 13th, 2005, 17:02
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 341
Thanks: 0
Thanked 0 Times in 0 Posts
Most likely that database that you are using is incorrectly configured to US (usually the default) or is hosted in the States

If you're using MS Access or SQL than you might try CONVERTing or CASTing the date to a UK format before specifiying the sort order.

I'd advise whenever working with dates between a webpage and a databse to always supply them in this format:

dd monthname yyyy

ex. 13 May 2005.

This method will store the correct date in the database independently of its configuration. Similalry when oulling the dates from the database, as mentioned before, get the converted to the correct format first by the query.
  #3 (permalink)  
Old May 13th, 2005, 17:29
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
but how can i use a convert method in a SELECT statement?

also, the database stores it in the correct way of dd/mm/yyyy hh:ss so why does it not order it properly?
  #4 (permalink)  
Old May 13th, 2005, 19:07
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 341
Thanks: 0
Thanked 0 Times in 0 Posts
MS Access or MS SQL database?
  #5 (permalink)  
Old May 13th, 2005, 19:55
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
MS Access but using SQL to query it
  #6 (permalink)  
Old May 13th, 2005, 21:49
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
woo sorted
  #7 (permalink)  
Old May 13th, 2005, 21:53
Reputable Member
Join Date: Aug 2003
Location: United Kingdom
Posts: 341
Thanks: 0
Thanked 0 Times in 0 Posts
both use slightly different SQL.

The Format function is what you'll need for MS Access:

http://www.techonthenet.com/access/f...ate/format.htm
  #8 (permalink)  
Old May 15th, 2005, 08:51
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
can anyone explain to me why i get data type mismatch in criteria expression on the following line:

set rs = conn.Execute("SELECT * FROM ftopics2 ORDER BY cdate(lastupdated) DESC")

lastupdated is a text field with the format "14 May 2005 12:24" in it....
  #9 (permalink)  
Old May 15th, 2005, 09:08
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
ok this is making no sense whatsoever!!!! it works for SQL statements but not for others...
  #10 (permalink)  
Old May 17th, 2005, 11:58
Up'n'Coming Member
Join Date: Feb 2004
Location: Woodbridge, UK
Age: 27
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Trebz Send a message via MSN to Trebz
CDate() is a VBScript Function


In SQL you need to do CONVERT(datetime, lastupdated)

I don't know why you are not just storing your date/time data in a datetime field?

No matter what the setup of SQL, it'll still be a valid date, you just pull it out and reformat it in your vbscript.
  #11 (permalink)  
Old May 17th, 2005, 13:15
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
storing it as a date didnt work for some reason it always displayed them in a funny order.

i get this error now: undefined function CONVERT in expression....
  #12 (permalink)  
Old May 17th, 2005, 13:50
Up'n'Coming Member
Join Date: Feb 2004
Location: Woodbridge, UK
Age: 27
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Trebz Send a message via MSN to Trebz
Sorry, didn't read some of those posts inbetween, CONVERT is a MSSQL function, won't work in Access.

I still dont think it should matter what country your dates are in, you should still be able to CDate in VBScript and then FormatDateTime to the way you want them, or even do Day(Date) MonthName(Month(Date)) Year(Date) etc... to extract the proper parts of the field in the proper order.
  #13 (permalink)  
Old May 17th, 2005, 16:06
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
its not the storing of the dates that is the problem - its displaying them. it doesnt display them in the correct order whatever i do....
  #14 (permalink)  
Old May 17th, 2005, 17:47
Up'n'Coming Member
Join Date: Feb 2004
Location: Woodbridge, UK
Age: 27
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Trebz Send a message via MSN to Trebz
Store the dates as dates int he database, and when you pull them out, put them through this function

Code: Select all
Function fnFixAccessDates(dtmDate)
  
  Dim strRetVal
  
  strRetVal = Day(dtmDate) & "/" & MonthName(Month(dtmDate)) & "/" & Year(dtmDate) & " " & Hour(dtmDate) & ":" & Minute(dtmDate) & ":" & second(dtmDate)
  
  fnFixAccessDates = strRetVal
  
End Function
  #15 (permalink)  
Old May 17th, 2005, 17:58
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to benbacardi Send a message via Skype™ to benbacardi
it still doesnt store them in the correct order though... posts on the 13th may come after posts on the 11th which they shouldnt....
  #16 (permalink)  
Old May 26th, 2005, 12:51
Up'n'Coming Member
Join Date: Feb 2004
Location: Woodbridge, UK
Age: 27
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Trebz Send a message via MSN to Trebz
What does your query look like?

You ought to have

Code: Select all
SELECT
	Col1,
	Col2,
	etc...
FROM dbo.MyTableName
ORDER BY myDateCol DESC
Which will give you your data sorted by date with the newest first.
Closed Thread

Tags
annoying, dates

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP dates simonb PHP Forum 11 Sep 5th, 2007 14:30
Days between 2 Dates birdy247 JavaScript Forum 1 Apr 19th, 2007 19:55
printing out dates riotman Classic ASP 0 May 23rd, 2006 20:47
dates in SQL spinal007 Databases 3 Nov 10th, 2004 09:32
dates benbacardi Classic ASP 2 Sep 14th, 2004 16:18


All times are GMT. The time now is 21:01.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43