Inserting Current Date & Time SQL Server DB using ASP
Inserting Current Date & Time SQL Server DB using ASP
am 15.06.2005 15:48:27 von MD Websunlimited
Hi All
I have an ASP page which needs to insert the current date and time in a sql
server database.
I used to use access and use to get
sTime = now()
but with my sql server data type set to datetime the above does not work
do i need to convert it into some kind of format
thanks
Re: Inserting Current Date & Time SQL Server DB using ASP
am 15.06.2005 16:00:01 von reb01501
JP SIngh wrote:
> Hi All
>
> I have an ASP page which needs to insert the current date and time in
> a sql server database.
>
> I used to use access and use to get
>
> sTime = now()
>
> but with my sql server data type set to datetime the above does not
> work
>
> do i need to convert it into some kind of format
>
GETDATE() is the function that returns the current date and time in T-SQL.
Just as in Access, datetimes in SQL Server are not stored with any format.
The storage in SQL Server is different: instead of the Double that Access
uses, SQL Server stores datetimes as paired integers: the firs integer
containing the number of days since the seed date, the second containing the
milliseconds since midnight. It is up to the client program to apply
formatting to the value retrieved from the database.
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Re: Inserting Current Date & Time SQL Server DB using ASP
am 15.06.2005 20:25:08 von Chris Hohmann
"Bob Barrows [MVP]" wrote in message
news:unZ9GKbcFHA.2648@TK2MSFTNGP10.phx.gbl...
> JP SIngh wrote:
>> Hi All
>>
>> I have an ASP page which needs to insert the current date and time in
>> a sql server database.
>>
>> I used to use access and use to get
>>
>> sTime = now()
>>
>> but with my sql server data type set to datetime the above does not
>> work
>>
>> do i need to convert it into some kind of format
>>
> GETDATE() is the function that returns the current date and time in T-SQL.
You could also use CURRENT_TIMESTAMP as it is functionally equivalent to
GETDATE() but has the benefit if being ANSI SQL compliant.
Re: Inserting Current Date & Time SQL Server DB using ASP
am 15.06.2005 20:34:49 von reb01501
Chris Hohmann wrote:
>>>
>> GETDATE() is the function that returns the current date and time in
>> T-SQL.
>
> You could also use CURRENT_TIMESTAMP as it is functionally equivalent
> to GETDATE() but has the benefit if being ANSI SQL compliant.
Yeah, I always forget that one. There's also the odbc functions that can
return time or date only ... but I can never remember their names. :-)
Bob
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Re: Inserting Current Date & Time SQL Server DB using ASP
am 15.06.2005 21:04:42 von Chris Hohmann
"Bob Barrows [MVP]" wrote in message
news:Od13qjdcFHA.2768@tk2msftngp13.phx.gbl...
> Chris Hohmann wrote:
>
>>>>
>>> GETDATE() is the function that returns the current date and time in
>>> T-SQL.
>>
>> You could also use CURRENT_TIMESTAMP as it is functionally equivalent
>> to GETDATE() but has the benefit if being ANSI SQL compliant.
>
> Yeah, I always forget that one. There's also the odbc functions that can
> return time or date only ... but I can never remember their names. :-)
Are you talking about escape clauses? If so, they're discussed under the
"Writing International Transact-SQL Statements" topic in BOL.
Re: Inserting Current Date & Time SQL Server DB using ASP
am 15.06.2005 21:49:45 von reb01501
Chris Hohmann wrote:
> "Bob Barrows [MVP]" wrote in message
> news:Od13qjdcFHA.2768@tk2msftngp13.phx.gbl...
>> Chris Hohmann wrote:
>>
>>>>>
>>>> GETDATE() is the function that returns the current date and time in
>>>> T-SQL.
>>>
>>> You could also use CURRENT_TIMESTAMP as it is functionally
>>> equivalent to GETDATE() but has the benefit if being ANSI SQL
>>> compliant.
>>
>> Yeah, I always forget that one. There's also the odbc functions that
>> can return time or date only ... but I can never remember their
>> names. :-)
>
> Are you talking about escape clauses? If so, they're discussed under
> the "Writing International Transact-SQL Statements" topic in BOL.
No. I'm talking about the fn... functions, like:
SELECT {fn CURDATE()}
I have no idea where these are documented.
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Re: Inserting Current Date & Time SQL Server DB using ASP
am 15.06.2005 21:52:26 von reb01501
Chris Hohmann wrote:
> "Bob Barrows [MVP]" wrote in message
> news:Od13qjdcFHA.2768@tk2msftngp13.phx.gbl...
>> Chris Hohmann wrote:
>>
>>>>>
>>>> GETDATE() is the function that returns the current date and time in
>>>> T-SQL.
>>>
>>> You could also use CURRENT_TIMESTAMP as it is functionally
>>> equivalent to GETDATE() but has the benefit if being ANSI SQL
>>> compliant.
>>
>> Yeah, I always forget that one. There's also the odbc functions that
>> can return time or date only ... but I can never remember their
>> names. :-)
>
Ah! Here's a link:
http://msdn.microsoft.com/library/default.asp?url=/library/e n-us/odbc/htm/odbctime__date__and_interval_functions.asp
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Re: Inserting Current Date & Time SQL Server DB using ASP
am 15.06.2005 23:30:04 von Chris Hohmann
"Bob Barrows [MVP]" wrote in message
news:OeryCPecFHA.2520@TK2MSFTNGP09.phx.gbl...
> Chris Hohmann wrote:
>> "Bob Barrows [MVP]" wrote in message
>> news:Od13qjdcFHA.2768@tk2msftngp13.phx.gbl...
>>> Chris Hohmann wrote:
>>>
>>>>>>
>>>>> GETDATE() is the function that returns the current date and time in
>>>>> T-SQL.
>>>>
>>>> You could also use CURRENT_TIMESTAMP as it is functionally
>>>> equivalent to GETDATE() but has the benefit if being ANSI SQL
>>>> compliant.
>>>
>>> Yeah, I always forget that one. There's also the odbc functions that
>>> can return time or date only ... but I can never remember their
>>> names. :-)
>>
> Ah! Here's a link:
> http://msdn.microsoft.com/library/default.asp?url=/library/e n-us/odbc/htm/odbctime__date__and_interval_functions.asp
>
> --
> Microsoft MVP -- ASP/ASP.NET
Oh, I see. Thanks for the link.