Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cast String as an Integer
#1
What am I overlooking here?  I'm wanting to do a date difference but can't remember/figure out how to cast string as int.
How can I do this?

Macro Macro5
Code:
Copy      Help
int spanDays
_s.timeformat("{yMMdd}")
_i=_s
TimeSpanGetParts sub.DateIntToDateTime(_i)-sub.DateIntToDateTime(210405) spanDays
out spanDays
end

#sub DateIntToDateTime
function'DateTime dateInt

;dateInt - date in decimal format, like 160103 (2016-01-03)

;note: year must be 2-digit, assuming that the actual year is 2000-2099.


DateTime r.FromParts(dateInt/10000%100+2000 dateInt/100%100 dateInt%100)
ret r
An old blog on QM coding and automation.

The Macro Hook
#2
is this it
_i=val(_s)
#3
YES!!!!   Yes, it is!

THANKS!!!!
An old blog on QM coding and automation.

The Macro Hook
#4
Ken you can accomplish this with alot less code
Code:
Copy      Help
DateTime dt.FromComputerTime dt1.FromStr("2021/04/05")
long spanDays; TimeSpanGetPartsTotal(dt-dt1 spanDays)
out spanDays
#5
THAT'S AWESOME!!!

Thanks!!!
An old blog on QM coding and automation.

The Macro Hook


Forum Jump:


Users browsing this thread: 1 Guest(s)