SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    i want to check the current system date with booking date

    Hi
    ALL

    I want to display the alert when user enters the time less than the system time and date should be current date and if the date is greater than current date it should ignore the alert box.
    Here is the code


    <script type="text/javascript">
    function check() {
    var now = new Date(),
    timeParts = document.contact_form.time.value.split(':'),
    userTime = new Date();
    var year = now.getFullYear();
    var month =now.getMonth()+1;
    var day = now.getDate();
    var today = year+"-"+month+"-"+day;
    var pickdate=document.contact_form.reqdate.value

    userTime.setHours(timeParts[0]);
    userTime.setMinutes(timeParts[1]);
    if (userTime < now && pickdate == today)
    {
    alert('Please enter the time greater than current time');
    }
    }
    </script>

    Please help me out to solve the problem


    Thanks
    md.Samiuddin

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,712
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by samiuddin.adse View Post
    I want to display the alert when user enters the time less than the system time and date should be current date and if the date is greater than current date it should ignore the alert box.
    That seems to work under certain circumstances.

    What seems to be the problem, your date handling?

    You can use the entered date to create the user date, then update the hour and minute sections. That way you can use the toDateString method to retrieve the date portion from the Date object, for easy comparison.

    Code javascript:
    var now = new Date();
     
    var timeParts = document.contact_form.time.value.split(':');
    var userDateTime = new Date(document.contact_form.reqdate.value);
    userDateTime.setHours(timeParts[0]);
    userDateTime.setMinutes(timeParts[1]);
     
    var isTodaysDate = userDateTime.toDateString() === now.toDateString();
    if (isTodaysDate && userDateTime < now) {
        ...
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •