473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to write datediff and format in c#

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
Nov 17 '05 #1
1 1563
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

"Vincent" <vh******@caribserve.net> wrote in message
news:#Q**************@TK2MSFTNGP14.phx.gbl...
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

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: KathyB | last post by:
Hi, not too swift with anything other than simple SQL statements, so I'm looking for some help. Using SQL Server 2000 with this stored proc: (@varCust varchar(50)) AS SET NOCOUNT ON
4
by: Paolo | last post by:
I am having some problem with a Year Function. I have form on which I have 4 field which indicate dates and an additional form which sums those dates: These are the fields: YEARS...
3
by: chanchito_cojones | last post by:
i have a question regarding the DateDiff function. I am quite new to access and seem to have hit a snag with this function. My problem is as follows: I have a table field that list a persons...
5
by: mcbill20 | last post by:
Hello all. I have a really basic question that I hope someone has a better answer for. I apologize in advance-- I know this is probably a really basic question but I am used to Oracle rathern than...
4
by: Brian Henry | last post by:
I am trying to find someones age within 2 months of their birthday on the given date for the run of the application Dim d_runOn As DateTime = #4/4/2005# Dim d_bday As DateTime = #6/26/1986# ...
9
by: laurenq uantrell | last post by:
I've gotten sort of fed up with dealing with regional date settings on the client side and am considering the following scheme - just wondering if anyone has a negative view of it or not: ...
3
by: Drum2001 | last post by:
I am running a query with the following SQL below: SELECT TimeClockHistory.ClockInDate, TimeClockHistory.ClockOutDate, TimeClockHistory.Employee, Sum(DateDiff("n",,))/60 AS TimeElapsed FROM...
7
by: Dean Earley | last post by:
I have the following code to get the number of seconds into a day given a date/time value: TValS = DateDiff("s", DateValue(StillDate), StillDate) StillDate is #04/05/2006 21:03:52#, and...
14
by: cmdolcet69 | last post by:
I'm trying to use the DateDiff function to calculate the difference whether a shift has been setup. when i run the code below with strFirstShiftEnd as a stringor date or datetime. I get an error...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.