Author Topic: Compare Now and a date and time in String format  (Read 2659 times)

0 Members and 1 Guest are viewing this topic.

Amsterdammed

  • Swamp Rat
  • Posts: 507
  • Revit MEP 2016 Acad2013, OPEN DCL
Compare Now and a date and time in String format
« 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
Bernd

Swift

  • Swamp Rat
  • Posts: 596
Compare Now and a date and time in String format
« Reply #1 on: August 23, 2005, 11:25:05 AM »
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.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
Compare Now and a date and time in String format
« Reply #2 on: August 23, 2005, 11:33:13 AM »
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?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Amsterdammed

  • Swamp Rat
  • Posts: 507
  • Revit MEP 2016 Acad2013, OPEN DCL
Compare Now and a date and time in String format
« Reply #3 on: August 23, 2005, 11:39:49 AM »
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..
Bernd

jjs

  • Guest
Compare Now and a date and time in String format
« Reply #4 on: August 23, 2005, 11:40:14 AM »
use the format function.
Code: [Select]

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

jjs

  • Guest
Compare Now and a date and time in String format
« Reply #5 on: August 23, 2005, 11:42:18 AM »
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

Amsterdammed

  • Swamp Rat
  • Posts: 507
  • Revit MEP 2016 Acad2013, OPEN DCL
Compare Now and a date and time in String format
« Reply #6 on: August 23, 2005, 12:49:05 PM »
Sorry JJs

but
Code: [Select]
strTimeNow=Format(strnow, HH:MM)
gives a syntax error
Bernd

jjs

  • Guest
Compare Now and a date and time in String format
« Reply #7 on: August 23, 2005, 01:25:55 PM »
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.

Amsterdammed

  • Swamp Rat
  • Posts: 507
  • Revit MEP 2016 Acad2013, OPEN DCL
Compare Now and a date and time in String format
« Reply #8 on: August 23, 2005, 01:49:58 PM »
OK
Bernd

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16727
  • Superior Stupidity at its best
Compare Now and a date and time in String format
« Reply #9 on: August 23, 2005, 01:52:41 PM »
I tested this and it works fine .. you are missing some quotes ...

Code: [Select]

strTimeNow = Format$(Now, "HH:MM")
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Amsterdammed

  • Swamp Rat
  • Posts: 507
  • Revit MEP 2016 Acad2013, OPEN DCL
Compare Now and a date and time in String format
« Reply #10 on: August 23, 2005, 02:27:56 PM »
That works Keith,

But i still don't know how to get the difference between the times in HH:MM format :?:
Bernd


Amsterdammed

  • Swamp Rat
  • Posts: 507
  • Revit MEP 2016 Acad2013, OPEN DCL
Compare Now and a date and time in String format
« Reply #12 on: August 25, 2005, 10:36:49 AM »
Thanks, Gentlemen
Bernd