473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

probleum in calculating the time difference

198 100+
Hi
i use Datediff() and it return only hours but i want total time with minutes and seconds at the same time
i use following code for all this and it works fine but when the the time came which i have mentioned in the coding produces wrong output
because the difference between is 1:13:52 but it is showing 12:33:52
how can i correct this please help


Dim Start As Date
Dim Finish As Date
Dim Duration As Date
Dim outStr As String
Dim Length As Integer

'Converting time values to dates
Start = CDate("5:53:05 PM")
Finish = CDate("6:26:57 PM")

'Find duration
Duration = Finish - Start
outStr = CStr(Duration)

'Convert to string an trim AM/PM indicator
Length = InStr(outStr, "AM")
outStr = Mid(CStr(Duration), 1, Length - 2)
MsgBox (outStr)
Apr 28 '08 #1
6 1806
debasisdas
8,127 Expert 4TB
How the difference is 1:13:52 ?

I think it is only 00:33:52.
Apr 28 '08 #2
veer
198 100+
Hi
sorry but it is showing 12:33:52
and i want to show only 00:33:52

please give some idea

thanks in advance


How the difference is 1:13:52 ?

I think it is only 00:33:52.
Apr 28 '08 #3
debasisdas
8,127 Expert 4TB
i don't understand the following lines of your code

Length = InStr(outStr, "AM")
outStr = Mid(CStr(Duration), 1, Length - 2)
Apr 28 '08 #4
kadghar
1,295 Expert 1GB
i don't understand the following lines of your code

Length = InStr(outStr, "AM")
outStr = Mid(CStr(Duration), 1, Length - 2)
Those lines will remove characters from Duration, starting from 1 position before an 'AM' appears for the first time.

i.e.

If Duration = "1:22:44 AM"
then
outStr = "1:22:44"

But if the string (Duration) does not have the string 'AM' in it,, then Length (which by the way is an awful name for a variable) will be zero, so the MID function will show an error.

I dont understand them neither, because the date format might change and Duration wont have 'AM' all times...

..so, to the OP, just have in mind the Duration shouldn't be over 12 hours, so you wont have 'AM' in the string. And make sure the format is always a desirable one.

HTH
Apr 28 '08 #5
veer
198 100+
Hi
thanks for reply
my duration is always eight hours
but if you have any sugestion regarding the date format please give

but my probleum is when the duration is less than one hour , then minutes and seconds are fine but hour should be in 00 format but it is displaying 12 insted of 00

e.g if duration is like 00:23:52
but with this code it is like 12:23:52
just give me suggestion how i will solve this probleum

i correct my code
dim Start as date
dim Finish as date
dim Duration as date
dim startdate,enddate as string

Start = CDate(StartDate)
Finish = CDate(EndDate)
Duration = Finish - Start
msgbox Duration




Those lines will remove characters from Duration, starting from 1 position before an 'AM' appears for the first time.

i.e.

If Duration = "1:22:44 AM"
then
outStr = "1:22:44"

But if the string (Duration) does not have the string 'AM' in it,, then Length (which by the way is an awful name for a variable) will be zero, so the MID function will show an error.

I dont understand them neither, because the date format might change and Duration wont have 'AM' all times...

..so, to the OP, just have in mind the Duration shouldn't be over 12 hours, so you wont have 'AM' in the string. And make sure the format is always a desirable one.

HTH
Apr 29 '08 #6
9815402440
180 100+
hi

use following to show duration

MsgBox Format(Duration, "hh:mm:ss")

regards
manpreet singh dhillon hoshiarpur
Apr 30 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Hans Gruber | last post by:
Hi all, I have been struggling with a problem all day, I have been unable to come up with a working solution. I want to write a function which takes 2 unix timestamps and calculates the...
1
by: Tony Williams | last post by:
I have a table with two fields, txtvalue (a number field) and txtmonth ( a date/time field). I want to create a report that shows the difference in value between the value in txtvalue in one value...
3
by: Ron Vecchi | last post by:
I need to calculate the age of a person based on a DateTime BirthDate I was thinking TimeSpan ts = DateTime.Now - BirthDate; //I can get the days but not years. // I could check each...
2
by: slinky | last post by:
Anyone know how to calculate the difference between two times displayed in two textboxes? I'm starting out with two textboxes: "txtCallTimeBegins" & "txtCallTimeEnds" this yielded: 6/7/2007...
2
by: veer | last post by:
hello expert i made a website which opens in ie6 and works fine but when i open it in ie7 it creates probleum the probleum is that i have a footer in my webpage , it automatically moves in the...
4
by: veer | last post by:
hi i have programe in which works fine for seaching the data from a file but when the i want to seach the word like" mögen ". In this word " ö " has some other kind of shap and my programe did not...
2
by: veer | last post by:
Hi i made a programe in which i want to calculate the total time from a column but when i declare a variable having datatype is "date" then the default value in this variable is "12:00:00: and...
3
by: veer | last post by:
Hi i have some probleum in reading the data from .val extension file when i manually open the file in notepad and just click on file option -> save -> close the txt file and then read the data...
3
by: mfaisalwarraich | last post by:
Hi everybody. I have some problem while calculating time. i have employees who are working on hourly basis. i want to calculate the time. for example if an employee start working at 11:00pm...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.