basic datetime picker date difference or subtract

Posted by Vanchi050585 under Regular Expressions on 8/31/2010 | Points: 10 | Views : 4126 | Status : [Member] | Replies : 5
hi all,

i was used two basic datetime picker in asp.net. I want to subtract or difference the date from 2nd control to 1st control (i mean basicdatetimepicker2.selecteddateformatted).

pls let me the sample for this

Thanks

Thanks
tvn



Responses

Posted by: Santosh4u on: 8/31/2010 [Member] Bronze | Points: 25

Up
0
Down
hi

u want the difference in day or month....

regards
santosh

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

Posted by: Vanchi050585 on: 9/1/2010 [Member] Starter | Points: 25

Up
0
Down
yes,

i want difference between in day

Thanks
tvn

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

Posted by: Amritha444 on: 9/1/2010 [Member] Starter | Points: 25

Up
0
Down
string strDateOfStart = "2008-08-10";
string strDateOfEnd = "2008-08-18";

DateTime dtStartDate = new DateTime(int.Parse(strDateOfStart.Substring(0, 4)),
int.Parse(strDateOfStart.Substring(5, 2)),
int.Parse(strDateOfStart.Substring(8, 2)));
DateTime dtEndDate = new DateTime(int.Parse(strDateOfEnd.Substring(0, 4)),
int.Parse(strDateOfEnd.Substring(5, 2)),
int.Parse(strDateOfEnd.Substring(8, 2)));
TimeSpan tsTimeDifference = dtEndDate.Subtract(dtStartDate);
string date = tsTimeDifference.ToString();
string[] str = date.Split(':');
string exactdate = str[0];
string[] strm = exactdate.Split('.');
txtTotalDays.Text= strm[0];


Try this..


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

Posted by: T.saravanan on: 9/1/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Vanchi,

TimeSpan ts=DateTimePicker1.Value.Date-DateTimePicker2.Value.Date;
string sDayDiff=ts.TotalDays.ToString();

This code helpful to you.

Thanks :)

Thanks,
T.Saravanan

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

Posted by: Santosh4u on: 9/1/2010 [Member] Bronze | Points: 25

Up
0
Down
hi tvn

it's very simple.

dim i as integer

i = basicdatetimepicker2.Value.DayOfYear - basicdatetimepicker1.Value.DayOfYear

try above code ,any problem let me know....

regards
Santosh


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

Login to post response