SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast MrK2's Avatar
    Join Date
    Jul 2001
    Location
    British Columbia
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Formatting Date in ASP

    I looked on a number of sites for some information about formatting the date in ASP, and found tons...unfortunately, the standard date function doesn't come out correctly.

    It shows (for September 4th, 2001):

    04/09/2001

    I want:

    09/04/2001

    I used the command rqsDate = FormatDateTime(Now(), vbShortDate)

    A number of sites have this working correctly...I'm wondering if it's been changed in IIS 5 or something? I'm using PWS from the Win98 CD. How can I format it to work correctly?

    Gracias.
    Last edited by MrK2; Sep 4, 2001 at 19:37.

  2. #2
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's not usually 09/04/2001? That's how it usually is for me.

    *confused* I'll have to look for some stuff on it.

    Anyone else have any ideas?
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  3. #3
    SitePoint Enthusiast hendo's Avatar
    Join Date
    Jun 2001
    Location
    Australia
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    G'Day!

    You'll need to do one of two things:

    1 - If you have access to the server, then you need to set the locality settings in the Control Panel.

    2 - Set the LCID of your web page as it runs. You can do this by having the following command.

    Session.LCID = xxxx

    Where xxxx is your Locality ID. E.G - 2057 is Great Britain, so your date is formatted dd/mm/yyyy. For US, try Session.LCID = 1033. The LCID lasts as long as the session does and must be addressed on a per session basis.

    Hope that helps!

    Have a good one.

    hendo
    Steve 'Hendo' Henderson
    EnVivo!CS: Fast and Affordable Web Content Management for ASP. 100% Script, No DLLs.
    www.netsystemsco.com

  4. #4
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey! dont know about you, but sometimes i get an error when using the session.LCID, so counter this, im writing a function to change the date from us to uk, or uk to us ill post it in about 5 mins

  5. #5
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heres the function:
    Code:
    <%
    Function changeDate(timeStr,loc)
    	splitterThingy = "/"
    	firstSlashPos = inStr(timeStr, splitterThingy)
    	secSlashPos = inStr(firstSlashPos, timeStr, splitterThingy)
    	yearSlashPos = inStr(secSlashPos + 1, timeStr, splitterThingy)
    	firstInfo = left(timeStr,(firstSlashPos - 1))
    	secInfo = mid(timeStr,firstSlashPos+1,(secSlashPos - 1))
    	yearInfo = mid(timeStr, (yearSlashPos + 1), len(timeStr))
    	If loc = "us" then
    		changeDate = secInfo & splitterThingy & firstInfo & splitterThingy & yearInfo
    	elseIf loc = "uk" then
    		changeDate = firstInfo & splitterThingy & secInfo & splitterThingy & yearInfo
    	end if
    end function
    response.write("uk -> us " & changeDate("05/09/2001","us") & "<br>")
    response.write("us -> uk " & changeDate("05/09/2001","uk") & "<br>")
    %>
    the date can only be changed from:
    us -> uk
    uk -> us


  6. #6
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The U.S Has four time zones for the continental U.S.
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  7. #7
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but dont they all format the date the same?

  8. #8
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    *sigh* sorry, was way off this morning.

    D', thanks a bunch. I'm allowed to be a little slow now and then, aren't I?
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  9. #9
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm... ill think about it goober

  10. #10
    SitePoint Wizard wdmny's Avatar
    Join Date
    Jul 2000
    Location
    Here
    Posts
    1,010
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In most countries the format is day/month/year. Like stated above, you need to set your locatity so you have the format for your country. If that doesn't work, on the regional settings you can choose the format for dates, money, and numbers as well.

  11. #11
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Newcastle, England
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    if you have problems using Session.LCID you can specify it as a directive at the start of each page. You may already use
    Code:
    <%@LANGUAGE="VBSCRIPT"%>
    You can either add to this or only specify the LCID, using one of the following:

    Code:
    <%@LANGUAGE="VBSCRIPT" LCID=2057%>
    or
    <%@LCID=2057%>
    This specifies the LCID for a particular page, so obviously you may need to repeat it throughout your code.

    Hope that helps .
    Nick Wilson [ - email - ]

  12. #12
    SitePoint Enthusiast MrK2's Avatar
    Join Date
    Jul 2001
    Location
    British Columbia
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for all the help everyone. I'm just learning ASP, so I test my scripts at home. I changed the date format under Regional Settings in Control Panel, and everything is working correctly now.


Bookmarks

Posting Permissions

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