Search This Blog

Wednesday, September 25, 2013

Find no of seconds between two dates

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace API
{
    public partial class datediff : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           // Sub();
            Sub1();
        }

        public void Sub()
        {

            DateTime dt1 = DateTime.Now;
            DateTime dt2 = new DateTime(2003, 4, 15);
            TimeSpan ts = dt1.Subtract(dt2);
            Response.Write(ts);

        }

        public void Sub1()
        {
            string strFileNAme = Server.MapPath(string.Format("~/cp.txt"));
            Response.Write(strFileNAme);
            Response.Write("</br>");
            FileInfo fi = new FileInfo(strFileNAme);
            DateTime dtSession = fi.LastWriteTime;
            Response.Write(dtSession);
            Response.Write("</br>");
            DateTime dt4 = DateTime.Now;
            Response.Write(dt4);
            Response.Write("</br>");
            TimeSpan diff = dt4 - dtSession;
            double seconds = diff.TotalSeconds;
            Response.Write(seconds);

        }
    }
       
}

OUTPUT:

D:\API\API\cp.txt
9/25/2013 3:13:47 PM
9/25/2013 4:19:23 PM
3935.7701132 

No comments :