TheSwamp
Code Red => VB(A) => Topic started by: Amsterdammed on August 23, 2005, 11:19:56 AM
-
Hello VBA experts,
I need to compare a start time and date , with is written in a string with the time and date provided by the “now” function. The Date is in European format.
So I have as example “23-8-2005 10:21:05” as a string expression and want it to compare with now, 23-8-2005 11:16:08.
When I try to format the string with Cdate I get an error with type mismatch.
What don’t I see here? :?: :?:
Thanks in advance,
Bernd
-
Hey Berend
I don't have time to work this out right now but I THINK you'll have to split the text into a date and a time and then compare the two.
-
You can compare the two, but it is hard to give you a solution when I don't know exactly what you want to have as a result ... do you want a difference in the two?
-
You are right, Keith
I should have add this line
m = DateDiff("n", logdur, Now)
Logdur is the string “23-8-2005 10:21:05”
M will be the time difference in minutes. Later I convert it in hours and minutes as User information in a UserForm..
-
use the format function.
function comparetimeanddate(strtimedategiven as string) as boolean
strNow = now
strDateNow=format (strnow, MM/DD/YY)
strTimeNow=Format(strnow, HH:MM)
strDategiven=format (strtimedategiven, MM/DD/YY)
strTimegiven=Format(strtimedategiven, HH:MM)
if strtimenow=strtimegiven and strdatenow=strdategiven then
bolequal=true
end if
comparetimeanddate=bolequal
end function
i made that all up. but it should be close i think
-
well, if you need the difference, that would be easy enough to change also.
function ... as string
get the difference between the days, then the times,
then return it as a string
-
Sorry JJs
but strTimeNow=Format(strnow, HH:MM)
gives a syntax error
-
you will have to look up how the format function works and what you need to pass to it. i was providing pseudo code that was pretty close to real code.
-
OK
-
I tested this and it works fine .. you are missing some quotes ...
strTimeNow = Format$(Now, "HH:MM")
-
That works Keith,
But i still don't know how to get the difference between the times in HH:MM format :?:
-
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctdatediff.asp
-
Thanks, Gentlemen