Quantcast
Channel: AutoHotkey Community
Viewing all articles
Browse latest Browse all 579

Ask for Help (v1) • Help with String Manipulation is needed.

$
0
0
I have 2 dates, they're both being copied from an application in string format.
They're both in YYYY-MM-DD format, I was able to split the string into substrings, and have every time period in its own variable. (YYYY = Year, MM = Month, etc...)

I am trying to compare them to see if a date is bigger/smaller than another, the problem is, they're both strings. I could not find a way to turn them into integers, but I believe it's because of how they are formatted.

CODE:

startDate := "2024-03-09"
endDate := "2024-03-10"

StringSplit, startComponents, startDate, -

startYear := startComponents1 ; "2024"
startMonth := startComponents2 ; "03"
startDay := startComponents3 ; "09"

StringSplit, endComponents, endDate, -

endYear := endComponents1 ; "2024"
endMonth := endComponents2 ; "03"
endDay := endComponents3 ; "10"


if (endMonth > startMonth && endDay > startDay) {
MsgBox, The end date is greater than the current date.
} else if (endMonth = startMonth && endDay = startDay) {
MsgBox, The end date is equal to the current date.
} else {
MsgBox, The end date is not greater than the current date.
}

return


This code always returns the last else block, I am assuming it's because I'm trying to use relational operators (<, >, =, etc...) on Strings. Although, I'm not sure how to format them correctly and how to turn them into integers, considering that any number below 9 is going to have a 0 before it, whether in months or days. Any help is greatly appreciated.

Statistics: Posted by caeee — Today, 12:57



Viewing all articles
Browse latest Browse all 579

Trending Articles