how to calculate how many days left

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mukeshrasm
    Contributor
    • Nov 2007
    • 254

    how to calculate how many days left

    Hi

    I want to calculate the number of days left for a particular event so when ever a user login to the website or visits the site may be able to view how many days left for that event.

    Example: an event will take place on 25 march 2010 so when user visit/logon to the website it will display remaining days for this event.
  • Bassem
    Contributor
    • Dec 2008
    • 344

    #2
    Hi,

    Please, look at this:
    Code:
        protected void Page_Load(object sender, EventArgs e)
        {
            DateTime anEven = new DateTime(2010, 3, 25);
            Label1.Text = anEven.Subtract(DateTime.Now).ToString();
            Label1.Text = anEven.Subtract(DateTime.Now).Days.ToString();
        }
    What happens here:
    1. Your event's date is assigned to a DataTime variable.
    2. Subtract Method is used to subtract a TimeSpan or DateTime.
    3. The Subtract Method's return type depends on what version of Subtract you use.
    4. Finally, assign the returned value to a label text property - after converting it to string.

    Thanks,
    Bassem

    Comment

    • mukeshrasm
      Contributor
      • Nov 2007
      • 254

      #3
      this code works fine now I wanted to show the days in images and for that I have images in image folder how can i use those image for days say number of days left is 12 then I want i should show the 1.gif and 2.gif to make it 12.

      Comment

      Working...