If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > A simple date problem?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-24-03, 16:47
manumu manumu is offline
Registered User
 
Join Date: Jul 2002
Posts: 4
A simple date problem?

using the date function in asp is supposed to give me the date as mm/dd/yyyy.
But for example today 24 march 2003 comes out as 3/24/2003.
but what I would like is it to come out as 03/24/2003.

The reason being when I store this into a sql database and sort it using a sql statement say by ascending order ,it comes out as

1/20/02
10/20/02
11/20/02
12/20/02
2/20/02
3/20/02

instead of

1/20/02
2/20/02
3/20/02
10/20/02
11/20/02
12/20/02

Any suggestions will be greatly appreciated .
Thanks a lot .
Reply With Quote
  #2 (permalink)  
Old 03-24-03, 17:11
Rbecerra Rbecerra is offline
Registered User
 
Join Date: Mar 2003
Posts: 8
Try this

Dim month_string,day_string,year_string,date_string

month_string=month(date)
if len(month_string)=1 then
month_string="0" & month_string
end if

day_string=day(date)
if len(day_string)=1 then
day_string="0" & day_string
end if


year_string=right(year(date),2)
date_string=month_string & "/" & day_string & "/" & year_string

'Now you use date_string
Reply With Quote
  #3 (permalink)  
Old 03-24-03, 17:57
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
> The reason being when I store this into a sql database
> and sort it using a sql statement say by ascending order,
> it comes out as ...

no

dates are stored in databases as some humungous integer measuring the number of days from january 1, 0000 or some other base date

dates are always converted, both going into a database (being stored) and coming out (being queried)

so if you are not getting the right display format on dates that you are querying, then you must change the way you format the date in the SELECT (you could also do it in ASP, i suppose, but it's much easier to do it in the SELECT)

if you are using Microsoft Access, check out the FORMAT function in the help

if you are using SQL Server, see CAST and CONVERT

you will probably want CONVERT(char(10),yourdate,101)

be careful sorting on it, because it is a string, and 03/24/2003 will come before 12/31/1999

you may want to keep yourdate in the SELECT list as well, and sort on that


rudy
http://rudy.ca/
Reply With Quote
  #4 (permalink)  
Old 03-25-03, 10:04
rhs98 rhs98 is offline
Super Moderator
 
Join Date: Feb 2002
Location: Hampshire, UK
Posts: 441
look up the set locale thing: you can change the date format using that. if not use formatdate()
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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