Date/Time stamp in SQL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bert

    Date/Time stamp in SQL

    I would like to store a Date/Time stamp in a SQL tabel
    Now only the Date is stred and not the time. How to I get the time also

    This is the code (There is more, but that works)

    atSQLexe ex=new atSQLexe()
    ex.addConnectio n=app.dbConnect ion
    sql="INSERT INTO Log (UserID, Date) VALUES (@UserID, @Date)"
    ex.addParm("@Us erID",userID)
    ex.addParm("@Da te", DateTime.Today)
    tr

    ex.ExecuteSQL(s ql)
    }
  • Kim Larsen

    #2
    Re: Date/Time stamp in SQL

    Try using

    DateTime.Now insted of DateTime.Today

    /Kim


    "Bert" <anonymous@disc ussions.microso ft.com> skrev i en meddelelse
    news:B3465988-5B68-4F55-82BB-658BA8B21B23@mi crosoft.com...[color=blue]
    > I would like to store a Date/Time stamp in a SQL tabel.
    > Now only the Date is stred and not the time. How to I get the time also?
    >
    > This is the code (There is more, but that works):
    >
    > atSQLexe ex=new atSQLexe();
    > ex.addConnectio n=app.dbConnect ion;
    > sql="INSERT INTO Log (UserID, Date) VALUES (@UserID, @Date)";
    > ex.addParm("@Us erID",userID);
    > ex.addParm("@Da te", DateTime.Today) ;
    > try
    > {
    > ex.ExecuteSQL(s ql);
    > }[/color]


    Comment

    • Wardeaux

      #3
      Re: Date/Time stamp in SQL

      Bert,
      if you have access to the table field definitions, you can set the default
      value of the desired field to "getdate()" , this retrieves the date/time on
      the SQL server automatically, no need to specify manually...
      hope this helps...
      wardeaux

      "Bert" <anonymous@disc ussions.microso ft.com> wrote in message
      news:B3465988-5B68-4F55-82BB-658BA8B21B23@mi crosoft.com...[color=blue]
      > I would like to store a Date/Time stamp in a SQL tabel.
      > Now only the Date is stred and not the time. How to I get the time also?
      >
      > This is the code (There is more, but that works):
      >
      > atSQLexe ex=new atSQLexe();
      > ex.addConnectio n=app.dbConnect ion;
      > sql="INSERT INTO Log (UserID, Date) VALUES (@UserID, @Date)";
      > ex.addParm("@Us erID",userID);
      > ex.addParm("@Da te", DateTime.Today) ;
      > try
      > {
      > ex.ExecuteSQL(s ql);
      > }[/color]


      Comment

      Working...