This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
4
Help subtracting two calendar dates as Strings.
Post Flair (click to view more posts with a particular flair)
Post Body
I am attempting to create a countdown between two days. For example an object was created on 05-12-2022 ( "dd/MM/yyyy" format)
I want this to live up until 12-12-2022 (a week later). How would you recommend I go about grabbing the number of days between each and starting a countdown of sorts (ie. 3 days left, 2 days left, etc).
This is how I'm grabbing the two dates currently, just don't know how to subtract them.
func removeEntryDate() -> String{
let nowDate = Date()
let endDate = Calendar.current.date(byAdding: .day, value: 7, to: Date())
var dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/MM/yyyy"
//return when we should delete past journal entry
var dateString = dateFormatter.string(from: endDate! as Date)
print(dateString)
return dateString
}
func currentDate() -> String {
let date = NSDate()
var dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/MM/yyyy"
var dateString = dateFormatter.string(from: date as Date)
//return when we should delete past journal entry
return dateString
}
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 1 year ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/swift/comme...