Hello All,
I my previous post we calculated difference between 2 Dates i.e. Sysdate and Other date that was stored in Database in Date format.
Recently i had to compare a date stored as varchar in database with sysdate.
Var storedDate = '30-11-1990' ;
I had to compare if the var storedDate is greater then current date or not, its very easy we just need to make the variable a date object.
Note: The format of string to be passed should be DD/MM/YYYY
var storedDate = '01/11/2019';
var dd2 = storedDate.substring(0,2);
var mm2 = storedDate.substring(3,5);
var yy2 = storedDate.substring(6,10);
var formatedStoredDate= dd2 + "/" + mm2 + "/" + yy2;
now we have date in DD/MM/YYYY format, lets convert this to date Object
var nDate = new Date (formatedStoredDate);
to compare this date with current date ,
var currDate = new Date ()
if (nDate > currDate )
{
// Stored date is Greater
}
else
{
//stored date is smaller
}
I my previous post we calculated difference between 2 Dates i.e. Sysdate and Other date that was stored in Database in Date format.
Recently i had to compare a date stored as varchar in database with sysdate.
Var storedDate = '30-11-1990' ;
I had to compare if the var storedDate is greater then current date or not, its very easy we just need to make the variable a date object.
Note: The format of string to be passed should be DD/MM/YYYY
var storedDate = '01/11/2019';
var dd2 = storedDate.substring(0,2);
var mm2 = storedDate.substring(3,5);
var yy2 = storedDate.substring(6,10);
var formatedStoredDate= dd2 + "/" + mm2 + "/" + yy2;
now we have date in DD/MM/YYYY format, lets convert this to date Object
var nDate = new Date (formatedStoredDate);
to compare this date with current date ,
var currDate = new Date ()
if (nDate > currDate )
{
// Stored date is Greater
}
else
{
//stored date is smaller
}