
- Swift Tutorial
- Swift - Home
- Swift - Overview
- Swift - Environment
- Swift - Basic Syntax
- Swift - Data Types
- Swift - Variables
- Swift - Optionals
- Swift - Tuples
- Swift - Constants
- Swift - Literals
- Swift - Operators
- Swift - Decision Making
- Swift - Loops
- Swift - Strings
- Swift - Characters
- Swift - Arrays
- Swift - Sets
- Swift - Dictionaries
- Swift - Functions
- Swift - Closures
- Swift - Enumerations
- Swift - Structures
- Swift - Classes
- Swift - Properties
- Swift - Methods
- Swift - Subscripts
- Swift - Inheritance
- Swift - Initialization
- Swift - Deinitialization
- Swift - ARC Overview
- Swift - Optional Chaining
- Swift - Type Casting
- Swift - Extensions
- Swift - Protocols
- Swift - Generics
- Swift - Access Control
- Swift Useful Resources
- Swift - Compile Online
- Swift - Quick Guide
- Swift - Useful Resources
- Swift - Discussion
How add 1 day to Date in swift?
To 1 day to a date in swift we need to create a date first. Once that date is created we have to add specific days to it. In this example we’ll see how we can achieve the same.
Let’s create a date first, let it be today,
let today = Date()
Now to modify this date we’ll use the add function with negative value,
let modifiedDate = Calendar.current.date(byAdding: .day, value: 1, to: today)!
Now to see the difference between both the dates, let’s add print statement for both of these. Our complete code should now look like this.
let today = Date() print(today) let modifiedDate = Calendar.current.date(byAdding: .day, value: 1, to: today)! print(modifiedDate)
When we run the above code on a playground simulator we get the following result, which shows exactly a difference of two hours in both the date, and the modified date.
- Related Articles
- How to add 1 day to the date in MySQL?
- How to add 1 day to a Date in iOS/iPhone?
- How to add a day to the date in MySQL?
- How to use date command in day to day practical usage
- JavaScript program to decrement a date by 1 day
- How to select rows in MySQL that are >= 1 DAY from the current date?
- How can we add day/s in the date stored in a column of MySQL table?
- How to add days to $Date in PHP?
- How to Add two Numbers in Swift Program?
- How to set the day of a date in JavaScript?
- How to add shadow on text swift?
- How to add constraints programmatically using Swift
- How to add months to a date in JavaScript?
- How to update only day portion of MySQL Date?
- How to Convert Numbers to Year/Month/Day or Date in Excel?

Advertisements