Results 1 to 4 of 4

Thread: Getdate

  1. #1
    Join Date
    May 2003
    Posts
    30

    Unhappy 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

  2. #2
    Join Date
    Nov 2002
    Location
    cornwall
    Posts
    187
    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

  3. #3
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    --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

  4. #4
    Join Date
    Feb 2003
    Location
    Aussie Land
    Posts
    114
    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
  •