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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. C# Date functions

C# Date functions

Scheduled Pinned Locked Moved C#
csharphelpdatabasetutorial
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.
  • B Offline
    B Offline
    Branislav Vidovic
    wrote on last edited by
    #1

    Hi, I am hving troubles with inserting Date in my database. I have a field in my table in the databse whicih is Date/Time format. For example if I want to insert s specific date (let's say it is 19th july 2007) i need to insert 19.7.2007. Now that is not the problem. I have a string which is formated correctly. It goes as "19.7.2007". But when I insert it to database it reports error, because the dataset for that table needs a varaiable that is Date format and not a string. In visual Basic.NET i used Cdate function for converting strings in dates. What functions should I use in C#?

    L M 2 Replies Last reply
    0
    • B Branislav Vidovic

      Hi, I am hving troubles with inserting Date in my database. I have a field in my table in the databse whicih is Date/Time format. For example if I want to insert s specific date (let's say it is 19th july 2007) i need to insert 19.7.2007. Now that is not the problem. I have a string which is formated correctly. It goes as "19.7.2007". But when I insert it to database it reports error, because the dataset for that table needs a varaiable that is Date format and not a string. In visual Basic.NET i used Cdate function for converting strings in dates. What functions should I use in C#?

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, .NET has a DateTime struct that holds both date and time information. And that is what everyone seems to be using to insert date information into a database (unless the field is defined as a string that is). :)

      Luc Pattyn


      try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


      1 Reply Last reply
      0
      • B Branislav Vidovic

        Hi, I am hving troubles with inserting Date in my database. I have a field in my table in the databse whicih is Date/Time format. For example if I want to insert s specific date (let's say it is 19th july 2007) i need to insert 19.7.2007. Now that is not the problem. I have a string which is formated correctly. It goes as "19.7.2007". But when I insert it to database it reports error, because the dataset for that table needs a varaiable that is Date format and not a string. In visual Basic.NET i used Cdate function for converting strings in dates. What functions should I use in C#?

        M Offline
        M Offline
        Mike Dimmick
        wrote on last edited by
        #3

        DateTime.Parse, DateTime.ParseExact, DateTime.TryParse, DateTime.TryParseExact. If you know the format, prefer (Try)ParseExact. Use the Try version if you would prefer to test whether the format matches rather than getting a FormatException exception.

        Stability. What an interesting concept. -- Chris Maunder

        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