• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

javascript problem

Hi experts,

        My requirement is entered date should be less than or equal to current date. Date format is 5-May-2011 . if i use var date=new Date() for current date ,i am getting date in different format. please help

 I am using following java script.

function date()
 {
 
 var mydate=document.getElementById("txt_Signeddate").value;

 var now =new Date();

 if(mydate>now)
 {
 alert('Signed date should be less than or equal to current date');
  return false;
 }
 else
 return true;
 //var Date2 = new Date(document.getElementById("txt_Signeddate").value);

 //alert(Date2);
 }
</script>
0
gpinfotech
Asked:
gpinfotech
1 Solution
 
AmickCommented:
Look at the "Comparing" section at http://www.javascripttoolbox.com/lib/date/examples.php
Lots of information surrounding dates at this site.
0
 
leakim971PluritechnicianCommented:
You need to convert your date
var months = {"may":4, "jan":0, "feb":1}
var mydate = document.getElementById("txt_Signeddate").value.split("-");
mydate = new Date(mydate[2],months[mydate[1]],mydate[0]);
 var now =new Date();

if(mydate>now) { alert('Signed date should be less than or equal
0
 
hieloCommented:
try:
function date()
{
      var mydate=String(document.getElementById("txt_Signeddate").value);
      mydate=new Date( Date.parse(mydate.replace(/\W/g,'')))
     
      var now =new Date();
      now.setHours(0)
      now.setMinutes(0)
      now.setSeconds(0)
      now.setMilliseconds(0)
      if(mydate>now)
      {
      	alert('Signed date should be less than or equal to current date');
       return false;
      }
return true;
}

Open in new window

0
 
gpinfotechAuthor Commented:
Thanks  alot,you saved my time
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now