Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 getDate with seconds

Author  Topic 

nic
Posting Yak Master

209 Posts

Posted - 2002-01-02 : 14:23:54
Hi,
I'm writing a sp that builds a sql statement using the getdate function, but it only returns the date and time to the minute. How can you get the seconds to be included? I also tried current_timestamp but it returned the same value.

Simple example:
CREATE PROCEDURE testSP
AS
print 'select * from table where date = ' + cast(current_timestamp As varchar)
GO

I tried char etc but it never returns the seconds.

Thanks in advance

Nic

Rita Bhatnagar
Posting Yak Master

172 Posts

Posted - 2002-01-02 : 14:28:37
look at convert function in bol.

Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2002-01-03 : 16:50:10
Why are you CASTing a datetime value as varchar? Is your date field in your table not of datetime data type? If you select getdate() or current_timestamp without casting it as a varchar you will get seconds and 3/1000 of seconds. Try your statement without the CAST.

--------------------------------------------------------------
1000 Posts, Here I come! I wonder what my new title will be...
Go to Top of Page

Rafiq
Starting Member

25 Posts

Posted - 2002-01-04 : 03:35:50
Hi,

It's not a big problem. Try to use GetDate(). It will solve your problem.

Regards,

Rafi
Go to Top of Page

ymurali
Starting Member

2 Posts

Posted - 2002-01-04 : 06:02:14
quote:

Hi,
I'm writing a sp that builds a sql statement using the getdate function, but it only returns the date and time to the minute. How can you get the seconds to be included? I also tried current_timestamp but it returned the same value.

Simple example:
CREATE PROCEDURE testSP
AS
print 'select * from table where date = ' + cast(current_timestamp As varchar)
GO

I tried char etc but it never returns the seconds.

Thanks in advance

Nic



Go to Top of Page

ymurali
Starting Member

2 Posts

Posted - 2002-01-04 : 06:04:00
Hi

u better check the version of sqlserver u r using,if i do a getdate() in sqlserver7.0 the output is 2002-01-04 10:56:35.457
murali

quote:

Hi,
I'm writing a sp that builds a sql statement using the getdate function, but it only returns the date and time to the minute. How can you get the seconds to be included? I also tried current_timestamp but it returned the same value.

Simple example:
CREATE PROCEDURE testSP
AS
print 'select * from table where date = ' + cast(current_timestamp As varchar)
GO

I tried char etc but it never returns the seconds.

Thanks in advance

Nic



Go to Top of Page
   

- Advertisement -