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. Web Development
  3. ASP.NET
  4. Insert Date and time in sql server 2008

Insert Date and time in sql server 2008

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasesql-serversysadmintutorial
6 Posts 4 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.
  • S Offline
    S Offline
    Salman Farrukh
    wrote on last edited by
    #1

    Hi,I am salman. I have 2 separate fields in sql server 2008 for date and time. one field is of type date and the other is time. In .net we have DateTime object but no separate objects for date and time so how to insert date and time in sql server 2008 through c#.net code? remember i can not insert string of date and time coz the data types in database are date,time not string. Best Regards, Salman Farrukh

    S P R 4 Replies Last reply
    0
    • S Salman Farrukh

      Hi,I am salman. I have 2 separate fields in sql server 2008 for date and time. one field is of type date and the other is time. In .net we have DateTime object but no separate objects for date and time so how to insert date and time in sql server 2008 through c#.net code? remember i can not insert string of date and time coz the data types in database are date,time not string. Best Regards, Salman Farrukh

      S Offline
      S Offline
      sarang_k
      wrote on last edited by
      #2

      In SQL server database there is a datatype datetime use that.It wil store date and time.

      1 Reply Last reply
      0
      • S Salman Farrukh

        Hi,I am salman. I have 2 separate fields in sql server 2008 for date and time. one field is of type date and the other is time. In .net we have DateTime object but no separate objects for date and time so how to insert date and time in sql server 2008 through c#.net code? remember i can not insert string of date and time coz the data types in database are date,time not string. Best Regards, Salman Farrukh

        P Offline
        P Offline
        PunkIsNotDead
        wrote on last edited by
        #3

        yes like sarang_k says!!! you only have to concat both values of date and time like a string and after

        Convert.ToDateTime(yourConcatString);

        and save it

        1 Reply Last reply
        0
        • S Salman Farrukh

          Hi,I am salman. I have 2 separate fields in sql server 2008 for date and time. one field is of type date and the other is time. In .net we have DateTime object but no separate objects for date and time so how to insert date and time in sql server 2008 through c#.net code? remember i can not insert string of date and time coz the data types in database are date,time not string. Best Regards, Salman Farrukh

          R Offline
          R Offline
          Richa_Soni
          wrote on last edited by
          #4

          Do want to create two fields date & time?

          S 1 Reply Last reply
          0
          • R Richa_Soni

            Do want to create two fields date & time?

            S Offline
            S Offline
            Salman Farrukh
            wrote on last edited by
            #5

            look in sql server 2008 we have three data types datetime,date,time. I want to store date in date field and time in time field.but not in datatime field.

            1 Reply Last reply
            0
            • S Salman Farrukh

              Hi,I am salman. I have 2 separate fields in sql server 2008 for date and time. one field is of type date and the other is time. In .net we have DateTime object but no separate objects for date and time so how to insert date and time in sql server 2008 through c#.net code? remember i can not insert string of date and time coz the data types in database are date,time not string. Best Regards, Salman Farrukh

              R Offline
              R Offline
              Richa_Soni
              wrote on last edited by
              #6

              i think this code helps you..... SELECT CAST('2007-05-08 12:35:29. 1234567 +12:15' AS time(7)) AS 'time' ,CAST('2007-05-08 12:35:29. 1234567 +12:15' AS date) AS 'date'; the output of this code is- Time 12:35:29. 1234567 Date 2007-05-08

              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