473,804 Members | 3,031 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1430
You can use the version of ToString that takes a format, i.e.

int i = int.Parse(d.ToS tring("dhhmmss" ));

Regards

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

nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.csharp/<AD************ *************** *******@microso ft.com>
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.publi c.dotnet.langua ges.csharp]
Nov 16 '05 #2
bill tie <bi*****@discus sions.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.co m>
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
2947
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", $ENV{ComputerName}) or die "Can't open Application EventLog\n"; $handle->GetNumber($recs) or die "Can't get number of EventLog records\n";
2
1352
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. Driving me crazy.. any help would be appreciated. Thanks <!DOCTYPE xiamSMS SYSTEM "Message.dtd"> <xiam> <deliverRequest id="10234690"> ''' Need to retrieve this number using ASP <to>test</to>
4
44382
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
1987
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 number of entries varies. I would welcome advice on a more elegant way of extracting all the date information (first date, second date, third date, etc and appending to another table, say tblDates) rather than the crude way I have used left
11
1937
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 grabs all the records I am after...now all I need to do is get some code that will allow me loop through each of these records shown by the query and pass certain fields from these records into the Body of my email command...which then emails...
4
2654
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 don't work for myself if you get my drift....anyways even if this is not asked of you...it might get you on friendly terms with the lawyers in the office The code is written to extract information from a table with contract information and divide...
4
3960
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 occurs a number of times, but not an exact match for the string above. Can you help please: see code #!C:\\Perl\\bin use File::Copy; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); ...
4
2428
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 19-15 Date 2008-05-06 Time 18-00
3
2274
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),'/','') truncate table bow_flat
0
9575
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10564
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10320
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10308
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10073
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6846
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5645
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2981
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.