Problem : siebel escript to compare two dates
My Requirement is to write a escript to compare the dates.whiich I am getting from the following sources
1st Date : order date from order BC in MM/DD/YYYY format
2nd date : 14 days before date from current date.. DD/MM/YYYY
After capturing the aboce two dates i need to write a escript in siebel to compare the dates to find which date is larger..
I have tried a sample code ..for the 2nd date mentioned above.
var DateObject = new Date();
var DateObject1 = new Date(DateObject – 1209600000);
var datebefore=DateObject1.get
Can anybody correct me or share the code for the aboce requirement.
Solution : siebel escript to compare two dates
Which is the recognized date format on your server? Assuming that it is the same as the first date (MM/DD/YYYY), you should first modify the second date string to be in the format of the first date string. You can do this by using the string.replace function to swap the DD and MM characters.
After that, the date strings can be easily compared by using the date.parse static function, which takes a date string, and returns the number of milliseconds to that date since the epoch (midnight GMT 01/01/1970).
// sDate1, string representation of date in format MM/DD/YYYY
// sDate2, string representation of date in format DD/MM/YYYY
// assuming the native format on the server is MM/DD/YYYY
// change the format of sDate2 to match sDate1 by swapping the DD and MM
// string.replace can change DD/MM/YYYY to MM/DD/YYYY using a regex
sDate2 = sDate2.replace (/\d{2}\/\d{2}\/\d{4}/, “$2/$1/$3”);
// compare the date values by parse each string with escript date.parse
if (Date.parse (sDate1) > Date.parse (sDate2))
{
// the first date is greater
}
else if (Date.parse (sDate2) > Date.parse (sDate1))
{
// the second date is greater
}
else // Date.parse (sDate1) == Date.parse (sDate2)
{
// the first and second dates are the same