Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Beginner having trouble with date display

In my class assignment we were shown that <% =monthname(month(now))%> displays the month as a string. We were asked to display the day that way (ie. Tuesday). dayname didn't work for me (I guessed) but I looked in my book and found weekdayname. But when I wrote out <% =weekdayname(day(now))%> , it says Saturday. Today is Monday. What am I doing wrong? In case it matters, the whole line of code is:
<% =weekdayname(day(now))%>, <% =day(now) & " " & monthname(month(now))%>, <% =year(now)%>

I know it's not elegant, but we were asked to the display the current date as:
Monday, 7 October, 2002
But my result is Saturday, 7 October, 2002
What am I doing wrong? and thank you so much!:-)

SuzyTall


Comments

  • vanithvanith Member Posts: 44
    [b][red]This message was edited by vanith at 2002-10-7 15:28:25[/red][/b][hr]
    : In my class assignment we were shown that <% =monthname(month(now))%> displays the month as a string. We were asked to display the day that way (ie. Tuesday). dayname didn't work for me (I guessed) but I looked in my book and found weekdayname. But when I wrote out <% =weekdayname(day(now))%> , it says Saturday. Today is Monday. What am I doing wrong? In case it matters, the whole line of code is:
    : <% =weekdayname(day(now))%>, <% =day(now) & " " & monthname(month(now))%>, <% =year(now)%>
    :




    : I know it's not elegant, but we were asked to the display the current date as:
    : Monday, 7 October, 2002
    : But my result is Saturday, 7 October, 2002
    : What am I doing wrong? and thank you so much!:-)
    :
    : SuzyTall
    :
    :
    :

    Hi Suzy!!
    I bet if you had tried this code tomorrow, you would have figured out the problem yourself. You would have got an "invalid procedure or argument" error message.

    This is because, the Weekdayname() function takes in only 1 to 7 as its arguments. 1 - Sunday, 2 - Monday..... 7- Saturday.

    The day() function will return you the date part [7] in "Monday, 7 October, 2002" which would be "Saturday" for weekdayname(). You should use another function called weekday() which will return the day of the week [in this case 2, which is "Monday"].


    [code]
    <%=weekdayname(weekday(now))%>
    [/code]


    If you would allow me to make your code a bit more elegant,

    [code]
    <%
    dim sWeekday
    dim sDate
    dim sMonth
    dim sYear
    dim sFormattedDate

    sWeekday = weekdayname(weekday(now))
    sDate = day(now)
    sMonth = monthname(month(now))
    sYear = year(now)

    sFormattedDate = sWeekday & ", " & sDate & " " & sMonth & ", " & sYear

    Response.Write sFormattedDate
    %>
    [/code]

    Enjoy your programming :-)

    :)heers,
    vanith

    PS: Try using another builtin vbscript function 'FormatDateTime'



  • Shawn CarterShawn Carter Member Posts: 0

    _______ ( http://forcoder.org ) free ebooks and video tutorials about [ JavaScript R C# Ruby Go Visual Basic .NET Java Scratch Perl C++ Delphi Swift PHP Assembly MATLAB Python Visual Basic Objective-C PL/SQL C Transact-SQL Ada FoxPro VBScript Rust Scala LabVIEW Crystal Prolog Logo D Hack F# Bash ABAP Alice COBOL Julia Fortran Lisp Kotlin ML Apex Dart Clojure Erlang Awk Lua Scheme SAS ] ___

Sign In or Register to comment.