[thelist] ADO Date Functionality
Anthony Baratta
Anthony at Baratta.com
Mon, 03 Jan 2000 14:54:33 -0800
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)
That's what I was looking for - but considering VB Scripts's tendency to
'do things for you', I'm not sure it would solve my problem. Here's what
I needed, found out and what I did:
1 - We are collecting birthdates from our registered members, so are
requiring a 4 digit year.
2 - We verified its a date by using the isDate(date) function.
3 - We test for a four digit year by using the Year(date) function and
checking to see if the year is greater than 1900 AND less than today's
current date.
4 - If it passes above tests we dump into database.
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.
e.g.
for each fld in objRS.Fields
IF fld.name = "Birthdate" THEN
DictPersonalInfo(fld.name) = Month(fld.value) & "/" &
Day(fld.value) & "/" & Year(fld.value)
ELSE
DictPersonalInfo(fld.name) = fld.value
END IF
Next
<TIP TYPE=DeBugging Code>
When working on large projects, take the time to create a GotHere() sub
routine or function. This routine will out put the state of all current
variables, objects, connections et.al. Then when you have the pesky bug
that just won't show itself, you can call the routine by just adding one
line of code strategically to your scripts.
</TIP>
--
Anthony Baratta