How to write datediff and format in c#

V

Vincent

Hi, in VB6 I have something like:
txtDays.Text = datediff("d",date1,date2)+1
txtLogdate.Text = format(Now,"dd-mmm-yyyy")

how do I write this in c# ?

Thanks
 
W

Wayne

if you do Date1 - Date2 you will receive a TimeSpan object. This has a days
property which is the number of days between the two dates.

so:
txtDays.Text = ((Date1-Date2).Days + 1).ToString(); //Not sure you still
need the +1 here, I added as you have it below.

and for the log date:
txtLogdate.Text = DateTime.Now(ToString("dd-mmm-yyyy");

--
Thanks
Wayne Sepega
Jacksonville, Fl

Enterprise Library Configuration Console Module Generator
http://workspaces.gotdotnet.com/elccmg

"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top