How to create a Date Picker in SwiftUI

Gurjit Singh
2 min readJan 16, 2024
Photo by Daria Shevtsova on Unsplash

Use a DatePicker when creating a view that enables users to choose both a calendar date and, if needed, a specific time.

In SwiftUI, you can use the DatePicker view to create a date picker. Here's an example of how to create a date picker and read values from it in SwiftUI:

import SwiftUI

struct ContentView: View {

@State private var selectedDate = Date()

var…

--

--

Gurjit Singh

I’m Computer Science graduate and an iOS Engineer who writes about Swift and iOS development. Follow me on twitter @gurjitpt and for more articles www.gurjit.co