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. Database & SysAdmin
  3. Database
  4. datetime

datetime

Scheduled Pinned Locked Moved Database
question
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.
  • L Offline
    L Offline
    lakshmi_sri
    wrote on last edited by
    #1

    how can i get the time and date in the datecreated field in a data table while inserting a record?

    E E 2 Replies Last reply
    0
    • L lakshmi_sri

      how can i get the time and date in the datecreated field in a data table while inserting a record?

      E Offline
      E Offline
      Edbert P
      wrote on last edited by
      #2

      You can return it as an OUT parameter if you are using a stored procedure, or do a select query on the record after you've inserted it. AFAIK there's no easier way to get this.

      "A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson "Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin Edbert Sydney, Australia

      1 Reply Last reply
      0
      • L lakshmi_sri

        how can i get the time and date in the datecreated field in a data table while inserting a record?

        E Offline
        E Offline
        Eric Dahlvang
        wrote on last edited by
        #3

        When you insert into the table, use getdate() as the value for the DateCreated field:

        insert into mytesttable (MyDateField) values (getdate())

        Or, to make a default value of the current datetime, in design view in the Enterprise Manager type (getdate()) in the Formula field for the table. Or, when you create the table in the Query Analyzer, do it this way:

        CREATE TABLE [MyTestTable] (
            [IDColumn] [int] IDENTITY (1, 1) NOT NULL ,
            [DateCreated] AS (getdate())
        ) ON [PRIMARY]

        --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

        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