Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I store only month and year in a smalldatetime column? 2

Status
Not open for further replies.

cesark

Programmer
Dec 20, 2003
621
0
0
Hi,

Is it posible to store in a smalldatetime column only month and year? Since I have a field in my web app that the user can specify day, month and year or only month and year.

Thanks
 
How about setting day of month to 1?

------
Theory: everybody knows everything, nothing works
Practice: everything works, nobody knows why

[banghead]
 
No, the time is always part of any the datetime datatypes. If you insert '02/17/2006' from your app or QA or whatever, without a time, it will add midnight as the time 00:00:00 so you will get '02/17/2006 00:00:00'

Jim
 
Hi vongrunt,

But if I set the default day to '01' how I will able to differentiate between real 01 day and not specified day?
 
You won't be able too.. Look in BOL, a smalldatetime will have month day and year and time to the second.
 
You could add another field to use to differentiate. Make it a bit datatype and have the value be 1 if it is a complete date and 0 if it is not.

Questions about posting. See faq183-874
Click here to help with Hurricane Relief
 
add another field (bit field) make it 1 if it's real and 0 if it's not real

Ok, done. I suppose it' s a good solution..

Thank you
 
Sorry, and then, to display that field?:
Code:
CREATE PROC retrieve_date
@order_id bigint, @date smalldatetime output, @filled_day bit,..
As

Select @date = Case
When filled_day = 1 Then the_date Else [b]??¿¿[/b] End , ...

From orders
Where order_id = @order_id

In the case filled_day = 0 (not filled) I would want to show only month and year, thus: 02/2006 or February/2006. How can I do this? Is there another better solution?

 
Make your output variable a varchar, and CAST the results of the CASE evaluation using DATEPART funcs.

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
Eschewing obfuscation diurnally.
 
Thanks, but I tried to format the date once in the web app and works fine. So, I return @filled_day field to app, if it is 0 (day not filled) I format the date to e.g April, 2006, and if it is 1 (day filled) I format the date to e.g. 07/04/2006.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top