Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 5th, 2004, 02:49 AM
Authorized User
 
Join Date: Jul 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to blueguy
Default is it possible? time substraction

i want to subtract this time 03.08.2004 14:01:22 from
04.08.2004 17:44:53. And obtain this format 27h.25
in Javascript

 
Old August 5th, 2004, 03:18 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hey blueguy,

I think this does what you want...

Code:
alert(GetTimeDiff(new Date("4 August 2004 17:44:53"), new Date("3 August 2004 14:01:22")));
function GetTimeDiff(d1, d2){
    var minDiff = Math.round(Math.abs(d1 - d2) / (1000 * 60));
    return Math.floor(minDiff / 60) + "h." + (minDiff % 60);
}
HTH,

Chris

 
Old August 5th, 2004, 03:55 AM
Authorized User
 
Join Date: Jul 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to blueguy
Default

But i changed time like that

alert(GetTimeDiff(new Date("04.08.2004 17:44:53"), new Date("03.08.2004 14:01:22")));

give me an error nah.na


 
Old August 5th, 2004, 04:12 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi blueguy,

That's because you need to give the Date constructor a date in an acceptable format. You can use a regular expression to convert your dates...

Code:
alert(GetTimeDiff(new Date(CleanDate("04.08.2004 17:44:53")), new Date(CleanDate("03.08.2004 14:01:22"))));

function CleanDate(d){
    return d.replace(/^(\d\d)\.(\d\d)\.(\d{4})/, "$2/$1/$3");
}

function GetTimeDiff(d1, d2){
    var minDiff = Math.round(Math.abs(d1 - d2) / (1000 * 60));
    return Math.floor(minDiff / 60) + "h." + (minDiff % 60);
}
Cheers,

Chris

 
Old August 5th, 2004, 08:46 AM
Authorized User
 
Join Date: Jul 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to blueguy
Default

i couldnt handle with that code with asp. And I just wantto use with vbscript and I give a Date from Table(database)
and subtract that date from now , use this result to update table

Tarih=Trim(Request.form("Date"))
Function Result(Date)
  Result = "Gecen Sure " & String(DateDiff("h", Now, Date))
End Function


                SQL="Update Table1 Set "
                SQL=SQL & "TimeDiffer='" & Result & "'"
                SQL=SQL & " Where SoruNo='" & SoruNo & "'


I write like this ,gives me an error like this
Microsoft VBScript runtime (0x800A01C2)
Wrong number of arguments or invalid property assignment: 'Result'



 
Old August 5th, 2004, 08:59 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi blueguy,

Quote:
quote:
 i couldnt handle with that code with asp. And I just wantto use with vbscript
Surely this should have been posted in an asp & not javascript forum?

I think you need:

Code:
Result = "Gecen Sure " & CStr(DateDiff("h", Now, Date))
ISO

Code:
Result = "Gecen Sure " & String(DateDiff("h", Now, Date))
Regards,

Chris






Similar Threads
Thread Thread Starter Forum Replies Last Post
synchronizing pocket pc time with desktop time bobbyrayudu83 C# 1 April 2nd, 2011 04:28 AM
Time Shift time in minus time out lechalas Beginning VB 6 1 August 11th, 2008 01:56 PM
time zone & day light time rajn ASP.NET 1.0 and 1.1 Professional 0 August 7th, 2007 05:02 PM
How to display the time(running time) in Excel swaroop Excel VBA 1 March 29th, 2007 01:56 AM
Using xs:time to generate time in desired format krayan001 XSLT 0 June 27th, 2005 04:28 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.