-
Getdate
Hi
I know this is going to sound really daft, but what is the easiest way of getting today's date without the time? Getdate() on it's own doesn't work because it always brings out the time. I know I'm missing something really basic but I can't figure it out.
Please help.
Thanks
-
Does this help?
declare @DateStr as varchar(30)
set @DateStr = cast(datepart(day,getdate()) as varchar(20)) +'-' + cast(datepart(month,getdate()) as varchar(20)) + '-' + cast(datepart(year,getdate()) as varchar(20))
print @DateStr
set @DateStr = cast(datepart(month,getdate()) as varchar(20)) +'-' + cast(datepart(day,getdate()) as varchar(20)) + '-' + cast(datepart(year,getdate()) as varchar(20))
print @DateStr
-
--Look into BOL for COnvert and Cast
select convert(varchar(12),getdate(),111) as mydate --yyyy/mm/dd
select convert(varchar(12),getdate(),103) as mydate --dd/mm/yyyy
-
though im not the thread start, thanks MAK. Had not for this thread, I'd still be doing tedious string concatenations just to get the date only.
--Maks Query
select replace( convert(varchar(12),getdate(),111), '/', '-') as mydate --yyyy-mm-dd
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|