Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. strange errror while parsing string to datetime in c#

strange errror while parsing string to datetime in c#

Scheduled Pinned Locked Moved C#
csharpdatabasevisual-studiojsonhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hosseinghazanfary
    wrote on last edited by
    #1

    hi dudes,i have an application written by c#,visual studio 2008,my database file is an access db.i have a maskedtextbox that user enters the date,(short date as 1388/02/15-it's persian date),i parse the string to date,and i insert some data into my database,icluding the parsed date.furthermore i want to update or insert records which their date is between that date and a month later.so after parsing the entered string into date,i seperate its year,month and day, so i can add a day in farsi calender format.everything's going right until in the loop i reach the date which is '1388/02/30', i get an exception which says 'string was not recognized as a valid dattime'.where's the problem? why all the days has not any problem while that specific day has the problem? i traced the application and i'm sure the string that is being parsed while the exception raises,is 1388/02/30. more desc:in persian (farsi) calender,6 first monthes of the year has 31 days,and the 6 last monthes has 30 days.

    I K 2 Replies Last reply
    0
    • H hosseinghazanfary

      hi dudes,i have an application written by c#,visual studio 2008,my database file is an access db.i have a maskedtextbox that user enters the date,(short date as 1388/02/15-it's persian date),i parse the string to date,and i insert some data into my database,icluding the parsed date.furthermore i want to update or insert records which their date is between that date and a month later.so after parsing the entered string into date,i seperate its year,month and day, so i can add a day in farsi calender format.everything's going right until in the loop i reach the date which is '1388/02/30', i get an exception which says 'string was not recognized as a valid dattime'.where's the problem? why all the days has not any problem while that specific day has the problem? i traced the application and i'm sure the string that is being parsed while the exception raises,is 1388/02/30. more desc:in persian (farsi) calender,6 first monthes of the year has 31 days,and the 6 last monthes has 30 days.

      I Offline
      I Offline
      Ian Shlasko
      wrote on last edited by
      #2

      Sounds like it's not using the Farsi calendar... In our calendar (Whatever you call it), 1388/02/30 would parse to February 30th, 1388... Since 1388 is a leap year, that month has 29 days. Make sure you're using the right DateTimeFormatInfo in the parsing function.

      Proud to have finally moved to the A-Ark. Which one are you in? Developer, Author (Guardians of Xen)

      1 Reply Last reply
      0
      • H hosseinghazanfary

        hi dudes,i have an application written by c#,visual studio 2008,my database file is an access db.i have a maskedtextbox that user enters the date,(short date as 1388/02/15-it's persian date),i parse the string to date,and i insert some data into my database,icluding the parsed date.furthermore i want to update or insert records which their date is between that date and a month later.so after parsing the entered string into date,i seperate its year,month and day, so i can add a day in farsi calender format.everything's going right until in the loop i reach the date which is '1388/02/30', i get an exception which says 'string was not recognized as a valid dattime'.where's the problem? why all the days has not any problem while that specific day has the problem? i traced the application and i'm sure the string that is being parsed while the exception raises,is 1388/02/30. more desc:in persian (farsi) calender,6 first monthes of the year has 31 days,and the 6 last monthes has 30 days.

        K Offline
        K Offline
        Keith Barrow
        wrote on last edited by
        #3

        I think these might help: Persian Calendar [^] Persian Calendar Members[^] The references refer to a type that is specifically designed for handling Persian dates as the month lengths are incompatable with Gregorian dates (ie xxxx/02/31 is valid). You will most probably need to convert to a standard DateTime (there is a ToDateTime method) when saving to database, otherwise you are in for a world of pain trying to get it to work.

        CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups