Date functions in Siebel eScript

If you have worked on any date field then you would be knowing that some of the standard date functions are not available in Siebel escript, like converting date from one format to another, adding number of business days to a particular date, comparing two dates etc.,

Here are some methods built in eScript that perform these operations.



1. AddDays
This function serves the purpose of DateAdd function available in other languages. Basically, when we need to add x days to a date, we can use this function.

function AddDays(myDate,days) 
{
/* Adds the number of Days specified in the input parameter ‘days’ 
 *  to the input parameter mydate and returns the new date
 * @param myDate,days
 * @return new Date
*
 */

    return new Date(myDate.getTime() + days*24*60*60*1000);
}

2. SubtractDays

This function helps in finding a backdated date.

function SubtractDays(myDate,days)
{
/**
 * Will subtract ‘days’ number of 
 * days from the input date and return the new date
 * @param myDate,days 
 * @return date 
 * @modified 
 */
 return new Date(myDate.getTime() - days*24*60*60*1000);
}


3. IsFutureDate
This function is used to find if any date is greater than today.

function IsFutureDate(mydate)
{
/*
 *  Function to check if a date is greater than today
 *  Returns 0 if Current Date is larger
 *  1 if Passed Variable is larger
*/

var istoday = new Date();   
var myM = ToInteger(mydate.getMonth()+1);
var myD = ToInteger(mydate.getDate());
var myY = ToInteger(mydate.getFullYear());
var toM = ToInteger(istoday.getMonth()+1);
var toD = ToInteger(istoday.getDate());
var toY = ToInteger(istoday.getFullYear()); 
if ((myY < toY)||((myY==toY)&&(myM < toM))||((myY==toY)&&(myM==toM)&&(myD < = toD)))
 { 
  return(0);
 }
else 
{ 
  return(1);
}
}

4. CompareDates This function is used to compare two dates and to find if one date is greater than or lesser than the other date.
function CompareDates(dte_from,dte_to)
{
/* Function to compare two dates.. will return 1 if dte_from is greater than dte_to else will return 0 */

var myM = ToInteger(dte_from.getMonth()+1);
var myD = ToInteger(dte_from.getDate());
var myY = ToInteger(dte_from.getFullYear());
var toM = ToInteger(dte_to.getMonth()+1);
var toD = ToInteger(dte_to.getDate());
var toY = ToInteger(dte_to.getFullYear()); 
if ((myY < toY)||((myY==toY)&&(myM < toM))||((myY==toY)&&(myM==toM)&&(myD < = toD)))
 { 
  return(0);
 }
else 
{ 
  return(1);
}
}

Comments (7)

Loading... Logging you in...
  • Logged in as
Jeena Tom's avatar

Jeena Tom · 796 weeks ago

Hi,
How do i check if 2 dates are in the same quarter or not. The quarter f the year is determined by the LOV value where start date of the quarter is the Description field of the LOV ad end date is Additional Description.
1 reply · active 796 weeks ago
Jeena, simplest way would be to compare both the dates with the LOV's and if both are larger than start date and less than end date then you will know that both lies in the same quarter
Jeena Tom's avatar

Jeena Tom · 795 weeks ago

Tejeshwer, can you pls give me detailed description. It could be good if u could help me with the comparison expressions, as i tried but was not able to get it...
Mark Spicer's avatar

Mark Spicer · 787 weeks ago

The SubtractDays function is not valid - if the number of days you are subtracting results in '0', you can have a date with a 0 value.
Thanks a lot. it worked like a charm!
Hi

How to convert Sunday, June 7, 2015/11:26:40 AM AST to MM/DD/YYYY HH:MM:SS

Regards
Syed
This is a very useful function to create websites such as blogs or journaling... it helps search engines to easily index them.

Post a new comment

Comments by

Other Siebel Blogs

siebel-admin-l @ IT - toolbox

siebel-dev-l @ IT - toolbox