473,387 Members | 1,757 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,387 software developers and data experts.

extracting number from date


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?

Nov 16 '05 #1
2 1415
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/<AD**********************************@microsoft.co m>
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]
Nov 16 '05 #2
bill tie <bi*****@discussions.microsoft.com> wrote:
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;

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

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

Similar topics

0
by: Gnaneshwar Babu | last post by:
Hi I am facing a problem with extracting event logs of win32 to a file. Am using the following code to extract eventlogs to file use Win32::EventLog; $handle=Win32::EventLog->new("System",...
2
by: Shawn | last post by:
I have an XML file that contains nodes and I'm having no problem extracting the information using ASP. However I can't seem to get the ID number from the deliverrequest node from the example below....
4
by: wolftor | last post by:
Month(date) shows the month number. Is there a way to get the month name ie. October? -- Regards, Peter
5
by: klall | last post by:
Hello. I need to extract date information from a memo field entered in the following way: 01/01/2005 - 31/12/2005 01/01/2004 - 31/12/2004 01/01/2003 - 31/12/2003 01/01/1996 - 31/12/1996. The...
11
by: Liam.M | last post by:
Hey guys, If anyone could spare sometime to help me out, it would be very much appreciated.....what I am trying to do is automate a "Command" that sends me an Email. I have created a Query that...
4
by: Kosmos | last post by:
Hey guys...as a relatively new programmer, I try to give back where I can. Below is the code for a useful program I believe many of you could use...just don't use the same exact code because...well I...
4
by: dexter48 | last post by:
Hi I'm searching for a string occurance in a text file. I find the string ok and write the results to a log file. But on the line above is also some information I need. How can i get that. The string...
4
by: poolboi | last post by:
hi guys i've having some problem extracting data from a text file example if i got a text file with infos like: Date 2008-05-01 Time 22-10 Date 2008-05-01 Time 21-00 Date 2008-05-02 Time...
3
benchpolo
by: benchpolo | last post by:
Sample A: Enrollment_20081211.txt Sample B: Enrollment_20081211_01.txt CODE declare @date varchar(8) , @cmd varchar(255) set @date = REPLACE(CONVERT(VARCHAR,GETDATE()-1,111),'/','') ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.