Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Derive current date&time for insert to SQL Server datetime fld

Status
Not open for further replies.

JohnBates

MIS
Feb 27, 2000
1,995
0
0
US
Hi ASP experts -

I have a DateTime datatype field in my SQL Server 7 table that I want to write to the record when the record is first written and any time it is subsequently updated.

Using ASP, is there a function that will put BOTH current date and time into a DateTime field?

This is what I'm doing, but all I get in the record is date:

datCurDate = Date()
.
.
.
the SQL Insert statement has CDate(datCurDate)


TimeValue(Now()) will give me only current time.

How can I get a value containing current date and time to use for inserting into my DateTime field?

Want to do this in ASP or vbScript.

Thanks, John




 
Say your table name is myTable and the date/time field is TodayNow:
Does,
Insert into myTable (TodayNow) values('" & now() & '")"

work?
 
Thanks for the fast reply Nsynan -

I'll try that in my ASP page tomorrow when I'm at work.
John
 
Hi,

You are using TimeValue(now()). So you are getting only Time value. Use only now() function. It gives both date and time.

response.write now()--This statement displays both Date and Time in the browser

bye,
Mallik
 
The sql server function for datetime is getdate(), you can put this directly in your update statement, unless there is some reason you want to control the date on the client side.

update yourtable
set yourdatetime = getdate()

insert into yourtable (yourdatetime) Values(getdate())
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top