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 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2003
    Location
    Rhondda Cynon Taff, Wales
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Date and Time script including...

    St, ND, Rd and TH with the date code E.G. 1st. Day Name included, Month Name included and A.M. or P.M. included.

    Code mod also needed - How can I add a 0 to the start of the minutes if they are below 10 of that it wil display 12:07 instead of 12:7? - Please dont move this code as I have postd a script I just need a modification.

    And, please tell me what you think or modifications I can make

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    HTML>
    <
    HEAD>
    <
    TITLE>Untitled</TITLE>
    <
    SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT"
    <!-- 
    var 
    ampm "a.m."
    var mydate = new Date() 
    var 
    monthday mydate.getDate()
    if (
    monthday == 4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||24||25||26||27||28||29||30)
    {
     var 
    monthday monthday "<SUP>th</SUP>";
    }
    else if (
    monthday == 1||21||31)
    {
     var 
    monthday monthday "<SUP>st</SUP>";
    }
    else if (
    monthday == 2||22)
    {
     var 
    monthday monthday "<SUP>nd</SUP>";
    }
    else if (
    monthday == 3||23)
    {
     var 
    monthday monthday "<SUP>rd</SUP>";
    }
    var 
    month mydate.getMonth() 
    if (
    month == 0)
    {
     var 
    month "January";
    }
    else if (
    month == 1)
    {
     var 
    month "Febuary";
    }
    else if (
    month == 2)
    {
     var 
    month "March";
    }
    else if (
    month == 3)
    {
     var 
    month "April";
    }
    else if (
    month == 4)
    {
     var 
    month "May";
    }
    else if (
    month == 5)
    {
     var 
    month "June";
    }
    else if (
    month == 6)
    {
     var 
    month "July";
    }
    else if (
    month == 7)
    {
     var 
    month "August";
    }
    else if (
    month == 8)
    {
     var 
    month "September";
    }
    else if (
    month == 9)
    {
     var 
    month "October";
    }
    else if (
    month == 10)
    {
     var 
    month "November";
    }
    else if (
    month == 11)
    {
     var 
    month "December";
    }
    var 
    day mydate.getDay() 
    if (
    day == 1)
    {
     var 
    day "Monday";
    }
    else if (
    day == 2)
    {
     var 
    day "Tuesday";
    }
    else if (
    day == 3)
    {
     var 
    day "Wednesday";
    }
    else if (
    day == 4)
    {
     var 
    day "Thursday";
    }
    else if (
    day == 5)
    {
     var 
    day "Friday";
    }
    else if (
    day == 6)
    {
     var 
    day "Saturday";
    }
    else if (
    day == 0)
    {
     var 
    day "Sunday";
    }
    var 
    year mydate.getYear() 
    var 
    hours mydate.getHours() 
    if (
    hours >= 12)
    {
    hours hours 12;
    ampm "p.m."
    }
    if (
    hours == 0)
    {
    hours 12;
    }
    var 
    minutes mydate.getMinutes() 
    document.write("The Time is: " hours ":" minutes +" " ampm
    document.write("<BR>" "The full date is: "day +", "  month " the " monthday "&nbsp;" year "<BR>")
    //--> 
    </SCRIPT>
    </HEAD>
    <BODY>
    </BODY>
    </HTML> 
    Last edited by sciguyryan; 10-19-2003 at 02:11 PM.
    Ryan Jones(sciguyryan)
    Visit us and chat at our forums - the Kidscript Forums

  • #2
    New Coder
    Join Date
    Aug 2003
    Location
    Rhondda Cynon Taff, Wales
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    its ok, solved - updated code: still want some comments though

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <
    HTML>
    <
    HEAD>
    <
    TITLE>Untitled</TITLE>
    <
    SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT"
    <!-- 
    var 
    ampm "a.m."
    var mydate = new Date() 
    var 
    monthday mydate.getDate()
    if (
    monthday == 4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||24||25||26||27||28||29||30)
    {
     var 
    monthday monthday "<SUP>th</SUP>";
    }
    else if (
    monthday == 1||21||31)
    {
     var 
    monthday monthday "<SUP>st</SUP>";
    }
    else if (
    monthday == 2||22)
    {
     var 
    monthday monthday "<SUP>nd</SUP>";
    }
    else if (
    monthday == 3||23)
    {
     var 
    monthday monthday "<SUP>rd</SUP>";
    }
    var 
    month mydate.getMonth() 
    if (
    month == 0)
    {
     var 
    month "January";
    }
    else if (
    month == 1)
    {
     var 
    month "Febuary";
    }
    else if (
    month == 2)
    {
     var 
    month "March";
    }
    else if (
    month == 3)
    {
     var 
    month "April";
    }
    else if (
    month == 4)
    {
     var 
    month "May";
    }
    else if (
    month == 5)
    {
     var 
    month "June";
    }
    else if (
    month == 6)
    {
     var 
    month "July";
    }
    else if (
    month == 7)
    {
     var 
    month "August";
    }
    else if (
    month == 8)
    {
     var 
    month "September";
    }
    else if (
    month == 9)
    {
     var 
    month "October";
    }
    else if (
    month == 10)
    {
     var 
    month "November";
    }
    else if (
    month == 11)
    {
     var 
    month "December";
    }
    var 
    day mydate.getDay() 
    if (
    day == 1)
    {
     var 
    day "Monday";
    }
    else if (
    day == 2)
    {
     var 
    day "Tuesday";
    }
    else if (
    day == 3)
    {
     var 
    day "Wednesday";
    }
    else if (
    day == 4)
    {
     var 
    day "Thursday";
    }
    else if (
    day == 5)
    {
     var 
    day "Friday";
    }
    else if (
    day == 6)
    {
     var 
    day "Saturday";
    }
    else if (
    day == 0)
    {
     var 
    day "Sunday";
    }
    var 
    year mydate.getYear() 
    var 
    hours mydate.getHours() 
    if (
    hours >= 12)
    {
    hours hours 12;
    ampm "p.m."
    }
    if (
    hours == 0)
    {
    hours 12;
    }
    var 
    minutes mydate.getMinutes() 
    if (
    minutes <= 9)
    {
    minutes "0" minutes;
    }
    document.write("The Time is: " hours ":" minutes +" " ampm
    document.write("<BR>" "The full date is: "day +", "  month " the " monthday "&nbsp;" year "<BR>")
    //--> 
    </SCRIPT>
    </HEAD>
    <BODY>
    </BODY>
    </HTML> 
    Ryan Jones(sciguyryan)
    Visit us and chat at our forums - the Kidscript Forums

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That is one LONG way of doing things....
    Month name:
    Code:
    function Date.prototype.getMonthName()
      { var months=['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
        return months[this.getMonth()];
      }
    Date suffix:
    Code:
    function Date.prototype.getDateSuffix()
      { var suffix=['st','nd','rd','th'];
        var dateMod = this.getDate%10;
        return suffix[dateMod<4?dateMod-1:3]; 
      }
    Last edited by Vladdy; 10-19-2003 at 03:29 PM.
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #4
    New Coder
    Join Date
    Aug 2003
    Location
    Rhondda Cynon Taff, Wales
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you I will cange it.
    Ryan Jones(sciguyryan)
    Visit us and chat at our forums - the Kidscript Forums

  • #5
    New Coder
    Join Date
    Aug 2003
    Location
    Rhondda Cynon Taff, Wales
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    One probem - I cant get it to work? - Can you help?
    Ryan Jones(sciguyryan)
    Visit us and chat at our forums - the Kidscript Forums

  • #6
    New Coder
    Join Date
    Aug 2003
    Location
    Rhondda Cynon Taff, Wales
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why was this moved? It was intended to be a posted script?
    Ryan Jones(sciguyryan)
    Visit us and chat at our forums - the Kidscript Forums


  •  

    Posting Permissions

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