extracting number from date

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Suppose it's Oct. 2, 2004 and time is 03:01:27.

I need a number (integer) that is in this form:

days hours minutes seconds

Using the example, the number will be:

2030127

Right now, I'm converting DateTime.Now to strings, concatenating them and
converting back to an integer:
"2" + "03" + "01" + "27"

Is there an easier way to do this?
 
You can use the version of ToString that takes a format, i.e.

int i = int.Parse(d.ToString("dhhmmss"));

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>


Suppose it's Oct. 2, 2004 and time is 03:01:27.

I need a number (integer) that is in this form:

days hours minutes seconds

Using the example, the number will be:

2030127

Right now, I'm converting DateTime.Now to strings, concatenating them and
converting back to an integer:
"2" + "03" + "01" + "27"

Is there an easier way to do this?


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/2004



[microsoft.public.dotnet.languages.csharp]
 
bill tie said:
Suppose it's Oct. 2, 2004 and time is 03:01:27.

I need a number (integer) that is in this form:

days hours minutes seconds

Using the example, the number will be:

2030127

Right now, I'm converting DateTime.Now to strings, concatenating them and
converting back to an integer:
"2" + "03" + "01" + "27"

Is there an easier way to do this?

As well as Richard's suggestion, you could use:

int value = dt.Day*1000000 +
dt.Hour*10000 +
dt.Minute*100 +
dt.Second;
 
Back
Top