Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
hi friends,
i have a date and an int. i want to subtract that integer from a given date .
 
[EDIT-> copied from the comment]
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 26-Dec-11 23:20pm
Edited 26-Dec-11 23:51pm
v2
Comments
Karthik Harve at 27-Dec-11 4:24am
   
your question is not clear. which integer you want to substract from date..?? show some code.
csemayank at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^].
  Permalink  
Comments
csemayank at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

try this
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
 
  Permalink  
v2
Comments
Karthik Harve at 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)

  Print Answers RSS
0 Maciej Los 315
1 OriginalGriff 273
2 Aajmot Sk 224
3 Marcin Kozub 210
4 Richard MacCutchan 200
0 OriginalGriff 7,853
1 Sergey Alexandrovich Kryukov 7,107
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 27 Dec 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100