Is there any easy way to truncate date like we can do in Oracle Database? For example, I need to set value starting from midnight. In Oracle I can do TRUNC(SYSDATE). But I cannot see similar way to do it in Swift. I checked StackOverflow and saw some examples with DateFormatter, Date Components with converting Date to String. I have also seen this question, but didn't understand how to handle Date (not NSDate) type and i
But I don't need String values. And I would like to avoid converting to string and back to Date. I just want to get three values:
Start of the current date (just like we do TRUNC(SYSDATE) in Oracle)
Start of the month (just like we do TRUNC(SYSDATE, 'MONTH') in Oracle)
Start of the year (just like we do TRUNC(SYSDATE, 'YEAR') in Oracle)
I tried this, but it does not return midnight:
let comp: DateComponents = Calendar.current.dateComponents([.year, .month, .day], from: Date())
let truncated = Calendar.current.date(from: comp)!
What should I do?