Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends,
i have a date and an int. i want to subtract that integer from a given date .

[EDIT-> copied from the comment]
C#
DateTime dt = new DateTime();
            dt = Calendar.SelectedDate;
            dt = dt.AddDays(Convert.ToInt32(txtadd.Text));
           lblgetdate.Text = dt.ToLongDateString();
            DateTime sDate = new DateTime();
            sDate = Calendar.SelectedDate;
            DateTime eDate = new DateTime();
            eDate = Convert.ToDateTime(lblgetdate.Text);
            DayOfWeek fWeek = DayOfWeek.Friday;

         
            int totCount = CountDayOcurrence(sDate, eDate, fWeek);
            lblweekday.Text = totCount.ToString();   

i want to subtract lblgetdate from lblweekday.
Posted
Updated 26-Dec-11 22:51pm
v2
Comments
Karthik Harve 27-Dec-11 4:24am    
your question is not clear. which integer you want to substract from date..?? show some code.
mayankshrivastava 27-Dec-11 4:31am    
DateTime dt = new DateTime();
dt = Calendar.SelectedDate;
dt = dt.AddDays(Convert.ToInt32(txtadd.Text));
lblgetdate.Text = dt.ToLongDateString();
DateTime sDate = new DateTime();
sDate = Calendar.SelectedDate;
DateTime eDate = new DateTime();
eDate = Convert.ToDateTime(lblgetdate.Text);
DayOfWeek fWeek = DayOfWeek.Friday;


int totCount = CountDayOcurrence(sDate, eDate, fWeek);
lblweekday.Text = totCount.ToString();

i want to subtract lblgetdate from lblweekday.

You can do that. However, which component of the DateTime do you want to subtract this integer from e.g. year / day / second and so on.

Basically, use the TimeSpan class to do the difference.
Use the FromDays, FromHours method or whichever one that you need to do the difference.
See here[^].
 
Share this answer
 
Comments
mayankshrivastava 27-Dec-11 4:36am    
DateTime dt = new DateTime();
dt = Calendar.SelectedDate;
dt = dt.AddDays(Convert.ToInt32(txtadd.Text));
lblgetdate.Text = dt.ToLongDateString();
DateTime sDate = new DateTime();
sDate = Calendar.SelectedDate;
DateTime eDate = new DateTime();
eDate = Convert.ToDateTime(lblgetdate.Text);
DayOfWeek fWeek = DayOfWeek.Friday;
int totCount = CountDayOcurrence(sDate, eDate, fWeek);
lblweekday.Text = totCount.ToString();

i want to subtract lblgetdate from lblweekday.
try this
VB
Dim dt As New Date
dt = "26-12-2011"
Dim a As Integer = 6
Dim a1 As Integer = 1

 While a1 <= Len(dt)
   If a = Mid(dt, a1, 1) Then
      MsgBox(a)
      Exit While
   End If
   a1 = a1 + 1
 End While
 
Share this answer
 
v2
Comments
Karthik Harve 27-Dec-11 4:52am    
[Edit] pre tags added.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900