SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Update Date/Time Button

    So I am trying to get an update date/time script to work with the server time, or a given time zone (-5 GMT). Right now, the script below references the local machines time. Thanks for any help on this topic!

    <html>
    <head>
    <script language="jscript" type="">
    function setcompleted()
    {
    var myDate = new Date();

    var str = (myDate.getMonth()+1) + "/" + pad(myDate.getDate()) + "/" + myDate.getFullYear();

    str += " " + pad(myDate.getHours()) + ":" + pad(myDate.getMinutes());

    document.forms[0].date_time.value=str;
    }
    function pad(num)
    {
    if (num &lt; 10)
    return "0" + num;
    else
    return num;
    }
    </script>

    </head>
    <body bgColor="#91a7b8" topmargin="3pt" bottommargin="3pt" leftmargin="3pt" rightmargin="3pt">
    <form>
    <input type="text" value="_currentdatetime" name="date_time" required="false"></input>
    <button language="jscript" onClick="return setcompleted()">Update Date/Time</button>
    </form>
    </body>
    </html>

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what is the purpose of this script? You could be going about this the wrong way. If you are wanting the server time, the only way to really get that is using Server Side Coding, ie PHP, ASP, ASP.Net etc.


  3. #3
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am wanting to use the server time, or a specific time zone (-5 GMT) to have the update date/time button refer to.

    My problem is simply that I have many users in different time zones, and when they update an entry, it doesn't make any logical sense to the other time zones. So to make it logical, if they are seeing the same time it can be related to one another.

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Updating an entry, I assume you are using a database? If so, then your server should provide the time. Thus by passing this issue altogether?


  5. #5
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am using a database, though the server provides the time on load I am creating this button so that the end user can press it just before they update a post, so the time is correct.

  6. #6
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When your user presses the button, I assume something is done Server Side to Update the Data. If so, then you can get the time then.


  7. #7
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    k, well I will keep searching for a solution. thanks.

  8. #8
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry to seem rude but that is the solution.

    If you want the time at the time of the user pressing the update button, the only sane and easy place to get it is when your server side code updates the data.


  9. #9
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just don't know how to get the server time using javascript, I just need a button that updates to the server time.

    This would be much easier if I had a server side language to use. Sadly, I don't.

  10. #10
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am now extremely confused. To update a database, you 99&#37; of the time use a Server Side Language, ASP, PHP, ASP.Net etc.


  11. #11
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,457
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    server time

    Javascript is a client-side language. That is, it runs on the user's machine, so it gets the time from the user's machine. The only way you could use javascript to get server time is to have it access a server-side script that provides it.
    How are you "updating an entry"?

  12. #12
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I should have explained earlier that I am using an online application to create forms, and display their output. I do not have access to the server-side language that sends the information to the database (ASP). I was hoping there was a way for me to get the servers time using javascript to update a field in my form before submitting it to the database.

  13. #13
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This type of value should be dealt with by the server side. You say you have no control over the ASP Code? I would seriously advise against what your wanting to do.

    But if you insist, you could make a note of the client time at page load, and then on the click of the button, subtract the load page time and the button click time, to get the difference in minutes, and then add this to the server time.


  14. #14
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the idea even though I don't think I want to go through with that process, it is logical. Perhaps instead of messing with the times so much I could have a count up script, and on the button click I would add that to the server time... we'll see what happens.

  15. #15
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,457
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    server time

    Maybe you could use a Perl CGI script?

  16. #16
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not sure what the server can support, nor do I know much cgi or perl.

  17. #17
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Server Time Solution

    I contacted the company that owns the application I am using, and they told me there were built in functions that would accomplish what I wanted to do.

    This is very application specific, and for this reason mods might want to take down this post.

    Thanks a lot for your help guys, I do appreciate it.


    <script language="jscript" type="text/Jscript">
    function setcompleted()
    {
    var str = '<currentdate/>' + ' ' + '<currenttime/>';

    document.forms[0].date_time.value=str;
    }
    </script>



    <input type="text" value="_currentdatetime" name="date_time" required="false" size="20" recipient="false" subject="true" message="false"></input>
    <button language="jscript" onClick="return setcompleted()">Update Date/Time</button>


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
  •