July 10, 2006 at 4:17 pm
HI. I have a table that has a date field and the developer wants the current date to be the default. when I set the default to GETDATE() in table designer, it populated the field with : 7/10/2006 5:09:00 PM. is there a way I can just pull in the data and not the time?
Thanks,
Juanita
July 10, 2006 at 4:53 pm
Juanita - you should use cast or convert to retrieve your date...with "convert" you can use formatting styles...
select convert(varchar, getdate(), 101)
**ASCII stupid question, get a stupid ANSI !!!**
July 10, 2006 at 5:03 pm
Don't force the server to perform type conversion from date to string & back again. Use this as teh default:
dateadd(d, 0, datediff(d, 0, getdate()))
July 11, 2006 at 6:02 am
That doesn't actually strip off the time portion though, or am I missing something?
July 11, 2006 at 8:55 am
Select getdate() As DateWithTime,
dateadd(d, 0, datediff(d, 0, getdate())) As DateOnly
Result:
DateWithTime DateOnly
2006-07-11 07:51:52.353 2006-07-11 00:00:00.000
July 11, 2006 at 8:56 am
Thank you for the suggestions!!
Juanita
July 14, 2006 at 8:54 am
Hmm. I see - I thought Juanita was actually trying to remove the time portion altogether, not just set it to 0.
July 17, 2006 at 4:40 am
You can't "strip off" time unless you store it as varchar.
The first post said it is a datetime column, ergo, it must store time but as 00:00:00.000
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy