tags:

views:

511

answers:

4

I'm a MySQL guy working on a SQL Server project, trying to get a datetime field to show the current time. In MySQL I'd use NOW() but it isn't accepting that.

INSERT INTO timelog (datetime_filed) VALUES (NOW())
+11  A: 

getdate() or getutcdate()

Daniel Schaffer
I'm out of votes, or i'd +1 for including UTC version
Greg Dean
I'll lend you a +1. :)
Bill Karwin
I voted for you Greg. =)
PEZ
+7  A: 

GetDate()

maxnk
A: 

You can also use CURRENT_TIMESTAMP, if you feel like being more ANSI compliant (though if you're porting code between database vendors, that'll be the least of your worries). It's exactly the same as GetDate() under the covers (see this question for more on that).

There's no ANSI equivalent for GetUTCDate(), however, which is probably the one you should be using if your app operates in more than a single time zone ...

Ian Varley
A: 
getdate()

is the direct equivalent, but you should always use UTC datetimes

getutcdate()

whether your app operates across timezones or not - otherwise you run the risk of screwing up date math at the spring/fall transitions

Steven A. Lowe