Click here to Skip to main content
12,065,888 members (39,738 online)
Rate this:
 
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
Mehdi Gholam297.9K
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.
csemayank 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 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160207.1 | Last Updated 27 Dec 2011
Copyright © CodeProject, 1999-2016
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