Tuesday, February 14, 2012

Date as part of primary key?

I have three items which make up the primary key:
ProjectNumber, Hardware, Date
Problem: The Date is formatted with date and time, how can I add a record and use just the date?
Currently I use GetDate() in my stored proc.
Mike BDates are not stored in any particular format. They are stored as a numeric value that indicates the number of days elapsed from a baseline date and the number of seconds elapsed since midnight (the decimal portion).

If you only want to store the whole-date portion, then instead of storing getdate store the results of this expression:

convert(char(10), getdate(), 120)

This will yield a time value equal to midnight. It's up to your interface to determine how the value is displayed.|||Dates are not stored in any particular format. They are stored as a numeric value that indicates the number of days elapsed from a baseline date and the number of seconds elapsed since midnight (the decimal portion).

If you only want to store the whole-date portion, then instead of storing getdate store the results of this expression:

convert(char(10), getdate(), 120)

This will yield a time value equal to midnight. It's up to your interface to determine how the value is displayed.
Exactly what I wanted, thank you!

Mike B

No comments:

Post a Comment