Click to See Complete Forum and Search --> : How to insert date and time in SQL Server


santulan
November 28th, 1999, 09:20 AM
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

czimmerman
November 28th, 1999, 11:19 PM
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

kieran_rush
November 29th, 1999, 02:21 PM
Why don't you try sendi the getdate() instruction to SQL, it will bring back the date and time

Regards