Link to home
Create AccountLog in
Avatar of Roberto Parker
Roberto ParkerFlag for Mexico

asked on

asp date to ms sql date

My asp script  has date1=now()
I need to transform it to be saved in a datetime ms sql field


Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

How are you accessing your database?  If it's with direct SQL, then "UPDATE tableName SET DateField = '" & Date1 & "' WHERE RecordID = " & RecordID

(I'm making assumptions, but you haven't provided much information to work with).
Classic asp will format dates like m/d/yyyy depending on your codepage.

While mssql server has date formated like yyyy-mm-dd hh:mm:ss  you can use Lee's SQL statement and it will update or insert as expected.

Just keep in mind that Lee's SQL is just to demo, you would never want to insert or update data like this and instead use prepared statements. 
Avatar of Roberto Parker

ASKER

Why not?
Because you will be open to an SQL injection. 
In SQL server, you can put
Column1=getdate()

Open in new window


to assign it with current date time.
ASKER CERTIFIED SOLUTION
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account