0

I have created a simple site using VS2013 and added a DateTime field to the AppUser model.

When testing the site locally using 28/08/2013 the site works fine.

When I deploy to Azure I get an error "String was not recognized as a valid DateTime." Changing the date to 08/28/2013 the site works fine on Azure but not locally.

Can anyone assist with this issue?

Many thanks for taking the time to look

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
tuppers
  • 98
  • 2
  • 8
  • This isn't a SQL Server issue. You are mixing American and European dates. Just don't use a localized date format, use the [unseparated](https://msdn.microsoft.com/en-us/library/ms180878(v=sql.105).aspx#UnseparatedStringFormat) format (20130828) for dates or the [ISO 8601](https://msdn.microsoft.com/en-us/library/ms180878(v=sql.105).aspx#ISO8601Format) format for date+time values. – Panagiotis Kanavos Mar 03 '15 at 11:28
  • Also avoid using raw string statements at all costs. Use parameterized queries to pass strongly-typed parameters and avoid all conversion problems. Parameterized queries are also *much* faster and just as easy to write as strings, if not easier – Panagiotis Kanavos Mar 03 '15 at 11:32
  • Can you point me in the direction of any examples of how best to handle dates with c#? – tuppers Mar 03 '15 at 12:34

1 Answers1

0

Well after some searching and many an hour agonising I found that I should be using DateTimeOffSet to handle my dates. I first found that utilising the example of the Identity Previous Pwd implementation I had no issue creating and updating records holding as date. The example can be found Implementing custom password policy using ASP.NET Identity

I also found this answer for using DateTimeOffSet: Datetime vs DateTimeOffset

Thanks for taking the time to look at my problem, hope this helps others.

Community
  • 1
  • 1
tuppers
  • 98
  • 2
  • 8