Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Date has wrong format Swift

I’m struggling with a problem here, i try to send data to server and i keep getting response "Date has wrong format. Use one of these formats instead: YYYY-MM-DD."

Here is my code example:

let postString: [String: String] = [
    "key": randomString(of: 16),
    "username": number.text!,
    "first_name": name.text!,
    "last_name": surname.text!,
    "birth_date": year.text! + month.text! + day.text!,
    "password": password.text!,
    "email": emailOpt.text!
]

i want to know how i can change it to "right" format

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I think you can convert year.text!+month.text!+day.text! to this:

"\(year.text!)-\(month.text!)-\(day.text!)"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading