Created
September 29, 2017 18:06
-
-
Save lugearma/33052b3cf845d1ff873f37b89dd5fea3 to your computer and use it in GitHub Desktop.
Convert String Date format to Date Type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let start = "2017-05-25" | |
let end = "2017-11-12" | |
let dateFormat = "yyyy-MM-dd" | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = dateFormat | |
let startDate = dateFormatter.date(from: start) | |
let endDate = dateFormatter.date(from: end) | |
let currentDate = Date() | |
guard let startDate = startDate, let endDate = endDate else { | |
fatalError("Date Format does not match ⚠️") | |
} | |
if startDate < currentDate && currentDate < endDate { | |
print("✅") | |
} else { | |
print("❌") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment