• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

How getDate() in SP just insert Date?

Hi

I have a stored proc in MSSQL 2005 to insert datetime datatype by getDate()

However, it inserted 2009-04-04 00:53:05.000

How can it just insert 2009-04-04 to the datetime field in the table?
0
techques
Asked:
techques
  • 2
  • 2
2 Solutions
 
catherinelouiseCommented:
you can use this:
 INSERT dateadd(day, 0, datediff(d,0,getdate()))

Open in new window

0
 
BrandonGalderisiCommented:
As catherine shows, you can use dateadd to strip the time component.  But when you store it as a datetime value, it will store the time (00:00:00.000) as midnight.  SQL Server 20005 doesn't have a DATE date type.  That wasn't added until SQL 2008.
0
 
BudrophiousCommented:
convert(varchar(50), getdate(), 102)
or
convert(varchar(50), getdate(), 111)
0
 
catherinelouiseCommented:
If the field is a datetime field it will still store the time as 00:00:00:000 with your example Budrophius, as Brandon explains above.  If not, then it will certainly be possible to store just the date.
0
 
BudrophiousCommented:
You are correct catherinelouise.  techques, as already mentioned, the date will be stored as a datetime.  To query the date in the format you requested use one of the convert functions I posted.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now