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
 Transact-SQL (2000)
 Getdate() not returning time

Author  Topic 

kimbelj
Starting Member

13 Posts

Posted - 2004-03-03 : 22:52:04
I've observed what seems to be odd behavior (or it's something I'm doing odd). I'm trying to something that is very simple - insert the date/time into a column defined as a datetime using getdate(), but I'm not always getting the time portion.

For example, I noticed on the customers (SQL 7) system the result of a getdate stored in a column is: dd/mm/yyyy 12:00:00 regardless of the current time. On my system (SQL 2000) I was getting this same behavior but at some point it changed to dd/mm/yyyy hh:mm:ss.xxx (not 12:00:00) as I would expect. The only thing I can think I did was to delete all the rows out of the table and start over, but I'm not certain. A colleague of mine (SQL 2000) is getting the same incorrect result as the customer.

Specifically, the code looks like this, where rss_level_date is the offending column. (I'm using a variable to hold the time since it is used later in the procedure and I want the time to be same for another field for comparison purposes. I don't think this should matter.)


declare @now as datetime
set @now = getdate()

UPDATE DM_Rate_Source SET rss_level= 'AR', rss_level_date=@now
WHERE(
(SELECT rss_mrs_id FROM DM_Rate_Source WHERE rss_id=@rss_id)=rss_mrs_id
AND rss_level = 'PU'
AND (rss_id not in (select rss_id from dm_rate_source
where (SELECT rss_effective_date FROM DM_Rate_Source WHERE rss_id=@rss_id)=rss_effective_date
AND (SELECT rss_level_date FROM DM_Rate_Source WHERE rss_id=@rss_id)=rss_level_date)))


DM_Rate_Source is defined as:


create table "DM_Rate_Source" (
"rss_id" int identity not null,
"rss_mrs_id" int not null,
"rss_blob_id" int null,
"rss_gmir" numeric(4,2) not null,
"rss_effective_date" datetime not null,
"rss_level" varchar(2) not null,
"rss_level_date" datetime not null,
"rss_date_added" datetime not null)


Any help is appreciated!!

-- Jeff

nr
SQLTeam MVY

12543 Posts

Posted - 2004-03-04 : 09:54:25
This looks like it should be OK.
How are you displaying the field to check it?

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

kimbelj
Starting Member

13 Posts

Posted - 2004-03-04 : 12:02:51
Thanks for the response!

I was looking at the data using QA and displaying using the DateTime::ToShortTimeString() C# function after retrieving the row by filling a DataSet. Both have the same result.

Anyways, I also just found out that it's working properly at our customer's site now, so I'm not sure what the deal is. I think I will leave it for now and attribute it to something other than the getdate() function. Perhaps their procedures were out of date.

-- Jeff
Go to Top of Page
   

- Advertisement -