CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 1999
    Location
    India-Delhi
    Posts
    106

    How to insert date and time in SQL Server

    Dear All,

    Please guide me how to insert current date in one field and current time in another field in SQL server. I used CAST, it works with date (It works but I am not clear) but not work at all with time.
    I selcted smalldatetime for date and timestamp for current time storage.

    regards,

    Santulan

  2. #2

    Re: How to insert date and time in SQL Server

    You can't use timestamp, as this is a binary value used internally by SQL server for the purposes of unique IDs.

    I played around with this a bit, trying to use a date field to hold just the time also inserted either the current date or a 'dummy' date (e.g., 1/1/1900). Therefore, unless I am doing something wrong, I would recommend using a text field to hold the current time. In VB, you can get a string with the current time through Format(Now, "Long Time") (or "Medium Time" or "Short Time")

    Charlie Zimmerman
    http://www.freevbcode.com


  3. #3
    Join Date
    Jun 1999
    Posts
    42

    Re: How to insert date and time in SQL Server

    Why don't you try sendi the getdate() instruction to SQL, it will bring back the date and time

    Regards


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

Featured