Shot in the dark

Hi All:

I am working with an OLE application which data can be manipulated with javascript. I have as a database native date format 1,049,200,679 For example.
This corresponds to  01-APR-2003 06:37:26.
My goal is to substract two such dates and return the number of month, days, hours and seconds in between.
I think that the easiest would be to work with the 1,049,200,679 format. For example: If I substract, 1,049,200,679 with  1,049,200,604 (01-APR-2003 06:36:44), I get  75. Now the question is....
How do I convert this 75 into a month,days, hours and seconds format.

Thanks!
Nickel
nickel2001Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dakydCommented:
Are you sure that 1,049,200,679 corresponds to 01-APR-2003 06:37:26?  The reason I ask is that those numbers look suspiciously close to the number of seconds since Jan 1, 1970 00:00:00.  Here's a little test script I wrote that illustrates this fact:

<script type="text/javascript">
var date = new Date(1049200679*1000);     // expects argument is in ms, multiply by 1000
var date2 = new Date(1049200604*1000);

document.write(date + "<br />" + date2);
</script>

When I did that, I got:
Tue Apr 1 04:37:59 PST 2003
Tue Apr 1 04:36:44 PST 2003

Hence my question, that seems way too close to be a coincidence.  If that's the case, then the difference between any two given numbers is equal to the number of seconds between those two dates.  It's also a bit of a stab in the dark, but hope it helps.
0
nickel2001Author Commented:
You are right. My assumptions about the format were wrong.
How do I go from the numbers of seconds between the two dates to a
days, hours, minutes format?

Thanks a lot for tackling this.

Nickel
0
dakydCommented:
Here's a sample script that will do the conversion for you.  It uses the absolute value of the difference, so it doesn't matter what order you put the dates in.  Hope that helps.

<script type="text/javascript">
function dateDiff(d1, d2)
{
  var totalSecs = Math.abs(d1 - d2);

  var days = parseInt(totalSecs / (60 * 60 * 24));
  totalSecs = totalSecs % (60 * 60 * 24);

  var hours = parseInt(totalSecs / (60 * 60));
  totalSecs = totalSecs % (60 * 60);

  var mins = parseInt(totalSecs / 60);
  totalSecs = totalSecs % 60;

  document.write("<h4 style='margin-bottom: 0'>For dates of " + d1 + " and " + d2 + ":</h4>");
  document.write("<p style='margin-top: 0'>Difference is " + days + " days, " + hours + " hours, " + mins + " minutes, and " + totalSecs + " seconds</p>");
}

dateDiff(1049200679, 1049200604);        // should return 1 min, 15 seconds
dateDiff(3661, 0);                  // should return 1 hour, 1 min, 1 second
dateDiff(90061, 0);                  // should return 1 day, 1 hour, 1 min, 1 second
dateDiff(310, 10);                  // should return 5 mins
</script>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nickel2001Author Commented:
Great. I'll check it out.

Thanks a lot,
Nickel
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.