Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13

Thread: FormatDateTime

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts

    FormatDateTime

    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

  • #2
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts
    would the vbgeneraldate do what you want?

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

    http://www.w3schools.com/asp/showasp...formatdatetime

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry - that displays it still as:

    MM/DD/YYYY

  • #4
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

    Code:
    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:
    Code:
    varDay/varMonth/varYear
    Last edited by jeskel; 10-31-2003 at 03:48 PM.

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    Bunbury W.A
    Posts
    157
    Thanks
    0
    Thanked 0 Times in 0 Posts

    this is what you need

    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

    %>

  • #6
    Regular Coder
    Join Date
    Jul 2002
    Location
    Bunbury W.A
    Posts
    157
    Thanks
    0
    Thanked 0 Times in 0 Posts

    to clarify further

    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
    %>

  • #7
    Regular Coder
    Join Date
    Oct 2003
    Location
    London, UK
    Posts
    411
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.
    Code:
    '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
    Marcus Tucker / www / blog
    Web Analyst Programmer / Voted SPF "ASP Guru"

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #9
    Regular Coder
    Join Date
    Oct 2003
    Location
    London, UK
    Posts
    411
    Thanks
    0
    Thanked 1 Time in 1 Post
    What exactly do you expect that line of code to do?!! Output the result? How? You haven't used "Response.Write" or "<%=" !!!

    Marcus Tucker / www / blog
    Web Analyst Programmer / Voted SPF "ASP Guru"

  • #10
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok - all sorted

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

  • #11
    Regular Coder
    Join Date
    Aug 2003
    Posts
    565
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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"),"-"))%>

  • #12
    Regular Coder
    Join Date
    Oct 2003
    Location
    London, UK
    Posts
    411
    Thanks
    0
    Thanked 1 Time in 1 Post
    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....
    Code:
    <% = Response.Write(LongDate(rsCustomer("DOB"),"-")) %>
    is equivalent to
    Code:
    <% 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.

    Marcus Tucker / www / blog
    Web Analyst Programmer / Voted SPF "ASP Guru"

  • #13
    Regular Coder
    Join Date
    Jul 2002
    Location
    Bunbury W.A
    Posts
    157
    Thanks
    0
    Thanked 0 Times in 0 Posts

    You Learn Something new everyday

    I didnt know that <% = was the same as response.write
    thanks
    Last edited by dawilis; 11-03-2003 at 11:11 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •