Results 1 to 3 of 3

Thread: Determining the format of a date

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Determining the format of a date

    Hi

    I have a date value that is being brought back from a database that I want to put into a datetimepicker on my form. Unfortunately some of the existing data is rather messy and some dates have only been put in as the year. This means that I get an error when trying to put something like 2003 into a datetime picker that is expecting a ddmmyyyy format.

    Is there any way that I can either check if the data is in the ddmmyyyy format or could I convert it to that format for populating the datetimepicker?

    Thanks.

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Determining the format of a date

    What kind of database are you working with? The column in your database should be of a date type to prevent this. You could check the length of the value to determine if only a year was retreived. You could also use the date.parseexact method, and handle the exception if an invalid date was retreived.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: Determining the format of a date

    It's a SQL Server DB. The original application was done in access and is not the best design ever and a lot of the data is quite messy. At the moment it's just been pulled over the SQL Server, with no changes made. The field I'm looking at is an nvarchar rather than a date so i guess maybe I should do some cleaning up of the DB itself. I'll try out your suggestions tho, thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width