[thelist] ADO Date Functionality

Scott Dexter sgd at ti3.com
Wed, 5 Jan 2000 06:00:27 -0600


ADO does lean on OLE automation and the regional settings on the server, so
you can cheat if you have access to the server-- change the regional
settings to use a 4 digit year in short dates:

Control Panel/Regional Settings --click on the "Date" tab, and add 'yy'
(without the quotes) to the short date style, so you change it from
something like "M/D/yy" to "M/D/yyyy" ...

that will coerce ADO and all the other OLE automation date routines (i.e.
almost everything running on the server) to use a four digit year in the
short dates. I did this on my workstation and our web servers cause i like
to look at 2000 instead of 00...

...or like Mike Ashton pointed out, you could format the date the way you
need it in the query, here's another way:

Select
otherfield1,otherfield2,(DatePart(month,DoBField)+'/'+DatePart(day,DoBField)
+'/'+DatePart(year,DoBField)) As DateOfBirth from ...

--This moves the work in your hack from the VBScript engine to the SQL
Server engine, which is probably faster ...

Unfortunately, the VBScript function formatdatetime() takes a limited set of
formats; from what I remember, you have short date (mm/dd/yyyy) and long
date (friday, Jan 1, 1999) and that's it --you gotta hack around it one way
or another (as you found out) ...

dunno if i'm helping, but i'm sharing what i know ...
sgd
--
think safely

-----Original Message-----
From: Anthony Baratta
To: thelist@lists.evolt.org
Sent: 1/3/2000 4:54 PM
Subject: Re: [thelist] ADO Date Functionality

Mike Ashton wrote:
> 
> One way of getting the format you want is to construct your query like
> this:
> 
> select to_char(DateField, 'YYYY-MM-DD HH24:MI:SS') as DateField1
>       From TableName (Query Analyzer)

We offer the user a chance to edit their profile. So we pull the data
out of the database, dump into form fields. However, VB Scripting shows
the four digit year as a two digit year for the current century (at
least the 20th century). What this means is that even though the date is
a four digit year, VB kindly shows you only 2 when asked the up front
way. e.g. <%=DictTestObject("Date")%> Shows 1/1/66 instead of 1/1/1966.
Yet for 1/1/2066 it shows 1/1/2066 - go figure.

So here's what I did:

When collecting date from DB, tested for date field during iteration
through RecordSet. Then cut the date up using the Day(), Month(), Year()
function and slammed it back together. Strangely, the Year() function
will return the correct 4 digit year versus the up front way.