DatePicker

I don’t know how to build datepicker. I want to build you can pick start and end date. Tell me.

Here is a simple view with 2 DatePickers:

import SwiftUI

extension Date {
    var justDate: String {
        let dateFormatter = DateFormatter()
        dateFormatter.dateStyle = .long
        dateFormatter.timeStyle = .none
        return dateFormatter.string(from: self)
    }
}

struct ContentView: View {
    @State private var start = Date()
    @State private var end = Date()

    var body: some View {
        List {
            Section(header: Text("Select Dates")) {
                DatePicker("Start date", selection: $start, displayedComponents: [.date])
                DatePicker("End date", selection: $end, displayedComponents: [.date])
            }

            Section(header: Text("Date Values")) {
                Text("Start: \(start.justDate)")
                Text("End: \(end.justDate)")
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
DatePicker
 
 
Q