Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

siebel escript to compare two dates

Posted on 2007-11-14
2
Medium Priority
?
15,842 Views
Last Modified: 2010-10-05
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.getMonth()+"/"+DateObject1.getDate() +"/"+DateObject1.getFullYear()+" "+DateObject1.getHours()+":"+DateObject1.getMinutes()+":"+DateObject1.getSeconds();

Can anybody correct  me or share the code for the aboce requirement.

Thanks a lot.


0
Comment
Question by:toharikr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 1

Accepted Solution

by:
linmm earned 1500 total points
ID: 20291305
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).

Should only be about 2-4 lines of script.  One to modify the date string, and 1-3 to compare the dates, depending on how you write it.  I've attached a snippet that should speak for itself.
	// 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
	}

Open in new window

0
 
LVL 1

Expert Comment

by:linmm
ID: 20291468
Had a little trouble understanding what you need exactly.  If you also need a quick way to get the date 14 days before today, here's a quick snippet for that.  I'm assuming that you do not want to look at times - just the dates.  If you want to be sensitive to the time of the day, leave out the last line which sets the time to midnight.

The only caveat is that since this is done using eScript (server script), it will use the date and time on the server, which may not be the same as the date and time that your order buscomp is returning.  The Order Date on the Order Entry - Orders business component returns a date and time in the time zone of the currently logged in user.

If you use a date object to compare the dates instead of a date string, you would get the number of milliseconds since the epoch using the date.getTime method (dt.getTime ()), instead of the date.parse method (Date.parse (sDate2)).

Hope this helps,
Mike

var dt = new Date (); // get the current date
dt.setTime (dt.getTime - 14 * 24 * 60 * 60 * 1000); // subtract 14 days
 
// dt is now exactly 14 days before the current time
 
dt.setHours (0, 0, 0, 0); // set the time to midnight on that day

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question