how to get only year from datetime datatype.. [Resolved]

Posted by Jayakumarkm under WPF on 4/8/2010 | Views : 3161 | Status : [Member] | Replies : 5
hi,

i assigned datetime datatype for an column(year).

if the user enter the year in the textbox(year column)
it appears as " mm/dd/yy " format..
i nedd only year from this to be saved into my db when user enter the year...


this is for wpf windows applciation,c#...

reagrds
jai




Responses

Posted by: Raja on: 4/8/2010 [Member] Starter

Up
0
Down

Resolved
You can use like below.

Suppose you have stored the datetime in thisDateTime variable then you can use
thisDateTime.Year.ToString();


Or

I would suggest not to store the year in DateTime variable rather store it into Integer variable field. That makes more sense when you have to store only year in the db.

Regards,
Raja, USA

Jayakumarkm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pavanandey on: 4/9/2010 [Member] Bronze

Up
0
Down
You can use

DateTime.Now.Year

Thanks
Pavan Kumar
Mark Answer if this fits the need

Jayakumarkm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumarkm on: 4/9/2010 [Member] Starter

Up
0
Down
hi pavan,

he might enter the year "1984" for that how can i do..

Jayakumarkm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumarkm on: 4/9/2010 [Member] Starter

Up
0
Down
hi raja!!!!!!!!!

thanks gud idea man..

Jayakumarkm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumarkm on: 4/9/2010 [Member] Starter

Up
0
Down
to store year as int ..
is an gud idea

Jayakumarkm, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response