...

View Full Version : FormatDateTime



holty
10-31-2003, 11:08 AM
Hi,

I have a date of birth coming out of an Access Db in the format

MM/DD/YYY

How can I change it to be: DD/MMM/YYYY?

I have tried using vbLongDate but it adds the day on the front!

Thanks

jeskel
10-31-2003, 11:32 AM
would the vbgeneraldate do what you want?

or check this link, that might help you...

http://www.w3schools.com/asp/showasp.asp?filename=demo_asp_formatdatetime

holty
10-31-2003, 11:42 AM
sorry - that displays it still as:

MM/DD/YYYY

jeskel
10-31-2003, 11:54 AM
ok... here is an idea, there is probably a very simple way to do it using server variables that I don't know but try this:

get your date as a var: varDate



dim varDate, varMonth, varDay, varYear

varMonth=left(varDate,2)
varDay=mid(varDate,4,2)
varYear=right(varDate,4)

and then the idea of your output would be:


varDay/varMonth/varYear

dawilis
11-01-2003, 09:40 AM
hope this helps

gettdate= rs("conDate") ' from a d/b query
'getdate = date() ' for current date
GetMonthName=MonthName(Month(getdate))
GetDay =Day(getdate)
getyear = year(getdate)
response.write GetDay &" "& GetMonthName &" "& getyear

%>

dawilis
11-01-2003, 09:49 AM
As an after thought
this will display the month as month Name wher you wnat the number so change code to this
see the difference
<%
getdate= rs("conDate")
'getdate = date()
GetMonthName=Month(getdate)
GetDay =Day(getdate)
getyear = year(getdate)
response.write GetDay &" "& GetMonthName &" "& getyear
End If
%>

M@rco
11-02-2003, 03:47 AM
That's almost right, but holty wants a 3 character month name, which is most easily achieved by simply including the optional parameter to MonthName() which you omitted. He also wanted forward slashes as date separators, but since one often requires different delimiters at different times (e.g. for user display, database insert, etc), I've parameterized that too.
'Convert date to unambiguous format (e.g. 10-Jan-2001)
Function LongDate(ByVal tmpDate, Byval Delimiter)
If IsDate(tmpDate) then
LongDate = Day(tmpDate) & Delimiter & MonthName(Month(tmpDate), True) & Delimiter & Year(tmpDate)
Else
LongDate = ""
End If
End Function

;)

holty
11-03-2003, 08:28 AM
Hi,

Thanks for all your help - I think I will use the function....

However when I try to call it I get syntax errors -

<%LongDate(rsCustomer("DOB"),'-')%>

What am I doing wrong?

M@rco
11-03-2003, 09:43 AM
What exactly do you expect that line of code to do?!! Output the result? How? You haven't used "Response.Write" or "<%=" !!!

;)

holty
11-03-2003, 10:25 AM
ok - all sorted

<%=response.Write(LongDate(rsCustomer("DOB"),"-"))%>

jeskel
11-03-2003, 10:33 AM
just let me point out that you don't need <%=response.write... why? because <%= is a shortcut for response.write... you might just write that code (as far as I'm concerned):

<%response.Write(LongDate(rsCustomer("DOB"),"-"))%>

M@rco
11-03-2003, 03:03 PM
Yes, I said one OR the other...! That line throws an error!! C'mon! This is basic stuff!

Perhaps it was just a typo, but in case not....
<% = Response.Write(LongDate(rsCustomer("DOB"),"-")) %>is equivalent to
<% Response.Write Response.Write(LongDate(rsCustomer("DOB"),"-")) %>

Since the inner response.write doesn't return a value, the outer response.write has nothing to output, and thus you get an error.

;)

dawilis
11-03-2003, 11:00 PM
I didnt know that <% = was the same as response.write
thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum