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

Thread: Date script

  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post

    Date script

    Hello

    I have a date script in an include file which works just fine:

    Code:
    <%
    Dim suffix
    Select Case Day(Date())
        Case 1,21,31: suffix = "st"
        Case 2,22: suffix = "nd"
        Case 3,23: suffix = "rd"
        Case Else: suffix = "th"
    End Select
    
    Response.Write "<p class=""show_date"">" & WeekdayName(Weekday(Date())) _
                 & " " & Day(Date()) & "<sup>" & suffix & "</sup>" _
                 & MonthName(Month(Date())) & "</p>"
    %>
    but I assume that because the site is hosted on US servers, it shows the date as a US one and not as a UK one.

    If I added
    Code:
    <%session.lcid=2057%>
    above my exisitng date script is that likely to work (I can't try it out just at the moment)?

    Thanks.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    That makes no sense.
    because the site is hosted on US servers, it shows the date as a US one and not as a UK one.
    Why does that matter??

    You aren't really USING the Date() itself. Just the Day(Date()), Weekday(Date()), and Month(Date()).

    And those have nothing whatsoever to do with the default display of the date.

    Read this that I wrote lo these many years ago (wow! eleven years plus..it has been a long time):
    http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=189

    If you read an understand that, you need to know that the Day(), Month(), etc., functions do *NOT* work on the formatted datetime value. The work on the internal format, which is completely independent of what the display looks like.

    Changing the Session.LCID changes *ONLY* the DISPLAY of the standard date and time output formats (and number formats, and a few other odd things). Nothing more.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    SteveH (05-25-2013)

  • #3
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Hello Old Pedant

    Many thanks for your comprehensive reply.

    Eleven years ago?! We all get older!

    That's a fairly in-depth article. It seems to me that you are making two important points especially:

    1) The display format must be specified in each place;

    2) Display does not mean 'stored'.

    Regarding (1), I think you are referring to applications, but I have actually included the 'Include' file on each separate WEB page and that works fine.

    Concerning point (2), I am not using a MS Access (or any other database) to store the date, but I am grateful that you have pointed out the difference.

    My question yesterday related ONLY to the display of the date.

    If I am in the UK and it's 2am and the day and date is today (for me), but the Web page is showing yesterday's day and date, it LOOKS inaccurate to the UK site visitor for the simple reason that it IS inaccurate because yesterday has passed.

    In other words, it would reflect poorly on the site as a whole - it would look as if the date on the site had not 'kept up' with real time, if you see what I mean!

    Thanks again, OP (in another life, maybe you could teach Astrophysics!).

    Take care

    Steve

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    Quote Originally Posted by SteveH View Post

    1) The display format must be specified in each place;

    2) Display does not mean 'stored'.

    Regarding (1), I think you are referring to applications, but I have actually included the 'Include' file on each separate WEB page and that works fine.
    Ummm...ASP (and VBScript) *IS* an application. More accurately, each *SESSION* is an application, from the standpoint of setting a Session LCID.

    Concerning point (2), I am not using a MS Access (or any other database) to store the date, but I am grateful that you have pointed out the difference.
    Look again. I carefully said the Access, Excel, *AND* VBSCRIPT (ASP!) use the same internal format.

    ******
    If I am in the UK and it's 2am and the day and date is today (for me), but the Web page is showing yesterday's day and date, it LOOKS inaccurate to the UK site visitor for the simple reason that it IS inaccurate because yesterday has passed.
    LOL! See, I did *NOT* read that into your question *AT ALL*!!

    I really thought you *were* talking about the *format* of the date!

    Okay...so what you need to do is find out what the *OFFSET* of the server's date *AND TIME* is compared to your date and time.

    So an easy way to do that is to simply create a web page where you do this:
    Code:
    Server: <%= Now() %>
    <hr/>
    <script type="text/javascript">
    document.write( "Local: " + ( new Date() ).toString() );
    See how many hours they are different (they may also be different by a few seconds, but that's likely your own computer clock being inaccurate).

    And then you will need to *adjust* the server time by that much.

    In other words, say it is 4AM server time and 10AM local time.

    So you need to add 6 hours.

    To do that, do this:
    Code:
    <%
    local = DateAdd( "h", 6, Now() )
    %>
    And then use local in place of Date() in all your other coding.

    So:
    Code:
    <%
    local = DateAdd( "h", 6, Now() )
    Dim suffix
    Select Case Day(local)
        Case 1,21,31: suffix = "st"
        Case 2,22: suffix = "nd"
        Case 3,23: suffix = "rd"
        Case Else: suffix = "th"
    End Select
    
    Response.Write "<p class=""show_date"">" & WeekdayName(Weekday(local)) _
                 & " " & Day(local) & "<sup>" & suffix & "</sup>" _
                 & MonthName(Month(local)) & "</p>"
    %>
    Of course, if the difference is 5 or 7 or 8 hours, just use that number, instead.
    Last edited by Old Pedant; 05-27-2013 at 04:26 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    SteveH (05-26-2013)

  • #5
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    That's very clever, OP. Thank you. Basically, I need to ask the hosting service what time they are in (I don't know what state they are in) and then use the difference in hours as you have them.

    Thank you!

    Steve

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,650
    Thanks
    80
    Thanked 4,638 Times in 4,600 Posts
    If you use my test page, as shown, you don't have to ask them. It will tell you.

    I have edited my post to put the test page in red, in case you missed it.

    Yes, that is a full and complete web page. Nothing more needs to be put on the page.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    SteveH (05-28-2013)

  • #7
    Regular Coder
    Join Date
    Nov 2005
    Posts
    750
    Thanks
    138
    Thanked 1 Time in 1 Post
    Hello Old Pedant

    Thanks for your great little script!

    I tested it and the server time is 8 hours behind, so I just replaced your '6' with '8' in the main code and it works like a treat to show the correct date (for me, I mean!) on the page.

    Thanks a million (again).

    Steve


  •  

    Posting Permissions

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