How to store date from Picker to Core Data?

47 Views Asked by At

I'd like to ask for an explanation why Dateformatter adds time and -1 day that I don't want. I need to save the date only in the format "yyyy-MM-dd" in the Date type field in Core Data

let dateFormat = DateFormatter()
dateFormat.dateFormat = "yyyy-MM-dd"
let formattedDate = dateFormat.string(from: myDatePicker.date)
let date = dateFormat.date(from: formattedDate)
    
print(formattedDate)
print(date!)

2023-10-08.
2023-10-07 22:00:00 +0000

I need to store only 2023-10-08

0

There are 0 best solutions below