Select to view content in your preferred language

Compare two dates without time in arcade

801
2
Jump to solution
09-14-2022 08:37 AM
Labels (1)
MosquitoGIS
Occasional Contributor

I am sure this has to exist and be simple and even basic (at least I would think), but I can't seem to find information anywhere.  I want to use Arcade to compare two dates (without time; just month, day, year) to see if they match.  The problem is that these dates I am working with have time associated with them.  So they don't match because the time doesn't match. For this accomplishment, I do not care for the time, only the month, day and year part of the date in the comparison.

I'm guessing it will be a conversion of those dates to a mmddyyyy only format within a variable, but I literally cannot find anything on how to accomplish this.

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

You can use Text() to format:

 

var d1 = Today()
var d2 = Now()

// Compare directly
Console(d1)
Console(d2)
Console("Dates are equal: " + (d1 == d2))

// Remove time and compare
var d1 = Date(Text(d1, "Y-MM-DD"))
var d2 = Date(Text(d2, "Y-MM-DD"))

Console(d1)
Console(d2)
Console("Dates are equal: " + (d1 == d2))

 

 

2022-09-14T00:00:00+02:00
2022-09-14T18:04:23.078+02:00
Dates are equal: false
2022-09-14T00:00:00+02:00 2022-09-14T00:00:00+02:00 Dates are equal: true

 


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

You can use Text() to format:

 

var d1 = Today()
var d2 = Now()

// Compare directly
Console(d1)
Console(d2)
Console("Dates are equal: " + (d1 == d2))

// Remove time and compare
var d1 = Date(Text(d1, "Y-MM-DD"))
var d2 = Date(Text(d2, "Y-MM-DD"))

Console(d1)
Console(d2)
Console("Dates are equal: " + (d1 == d2))

 

 

2022-09-14T00:00:00+02:00
2022-09-14T18:04:23.078+02:00
Dates are equal: false
2022-09-14T00:00:00+02:00 2022-09-14T00:00:00+02:00 Dates are equal: true

 


Have a great day!
Johannes
MosquitoGIS
Occasional Contributor

Fantastic!  Thank you kindly! 🙂

0 Kudos