473,799 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to get a Date Breakdown

I am trying to get a overall difference on two dates,

I can get the difference in Years, Months, Weeks, Days, Hours, Minutes,
Seconds, no problems...

What I cannot seem to figure out is how to get:

2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds.

The hardest part of that, the part I cannot figure out, is the Month
section... all the others are static, defined length components, but Months
change, are all different...

Help! anyone know how you do this? I am stuck...

Thanks So Much for your Help!

Atley
Nov 20 '05
16 1641
aha
you can do somthing like this...

dim date1 as datetime
dim date2 as datetime

dim ticks1 as long = date1.ticks
dim ticks2 as long = date2.ticks
Dim dt As New DateTime(math.a bs(ticks1 - ticks2))
Dim msg As String = "Differnce is:" & vbCrLf & _
"years: " & (dt.Year - 1) & vbCrLf & _
"months: " & (dt.Month - 1) & vbCrLf & _
"days: " & (dt.Day - 1) & vbCrLf & _
"hours: " & dt.Hour & vbCrLf & _
"minutes: " & dt.Minute & vbCrLf & _
"seconds: " & dt.Second

doing -1 for year, month and day:
new datetime(ticks as long) -> gives you a date, not a timespan
and the date is calculated as the number of ticks since 01-01-0001 00:00:00
so doing -1 for day, month and year gives you the remaining time for each
datetime part

isn't that kewl :-)
something not so kewl
try this
date1 = now
date2 = date1.addYear(1 )

result everything 0 except for year... and day (also 1)

tried a little with other "year-add's"
90 -> year=90, day=1
99 -> year=99, day=0

wellwell, bug for small number of add years only?
or am I missing something?

"Atley" <at*****@hotmai l.com> wrote in message
news:eY******** ******@TK2MSFTN GP10.phx.gbl... Thanks, but i can get the DateDiff several different ways, the problem is
with the breakdown into how much time is left as a rundown ie 1 year, 2
months, 1 week, 3 days, 6 hours, 23 minutes, 41 seconds...

"Dominique Vandensteen" <domi.vds_inser t@tralala_tenfo rce.com> wrote in
message news:OK******** *****@TK2MSFTNG P11.phx.gbl...
something like this?

dim date1 as datetime
dim date2 as datetime

dim ticks1 as long = date1.ticks
dim ticks2 as long = date2.ticks

dim difference as new timespan(math.a bs(ticks1 - ticks2))
Dominique


"Atley" <at*****@hotmai l.com> wrote in message
news:OI******** ******@TK2MSFTN GP12.phx.gbl...
I am trying to get a overall difference on two dates,

I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, Seconds, no problems...

What I cannot seem to figure out is how to get:

2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds.

The hardest part of that, the part I cannot figure out, is the Month
section... all the others are static, defined length components, but

Months
change, are all different...

Help! anyone know how you do this? I am stuck...

Thanks So Much for your Help!

Atley



Nov 20 '05 #11
Dominique,
You know you can shorten that to:
dim date1 as datetime
dim date2 as datetime

dim difference as timespan = date2.Subtract( date1)
Which assumes that date2 is after date1.

Hope this helps
Jay

"Dominique Vandensteen" <domi.vds_inser t@tralala_tenfo rce.com> wrote in
message news:OK******** *****@TK2MSFTNG P11.phx.gbl... something like this?

dim date1 as datetime
dim date2 as datetime

dim ticks1 as long = date1.ticks
dim ticks2 as long = date2.ticks

dim difference as new timespan(math.a bs(ticks1 - ticks2))
Dominique


"Atley" <at*****@hotmai l.com> wrote in message
news:OI******** ******@TK2MSFTN GP12.phx.gbl...
I am trying to get a overall difference on two dates,

I can get the difference in Years, Months, Weeks, Days, Hours, Minutes,
Seconds, no problems...

What I cannot seem to figure out is how to get:

2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds.

The hardest part of that, the part I cannot figure out, is the Month
section... all the others are static, defined length components, but

Months
change, are all different...

Help! anyone know how you do this? I am stuck...

Thanks So Much for your Help!

Atley


Nov 20 '05 #12
Dominique,
How about
Dim difference as TimeSpan = date2.Subtract( date1)
difference = difference.Dura tion() ' correct to positive offset
Now years is difference.Days/365 (ignoring leap year effects 365
days/year)
Days = difference.Days Mod 365
hours, minutes and seconds are directly readable from the timespan.

Ron Allen
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:ep******** ******@TK2MSFTN GP09.phx.gbl...
Dominique,
You know you can shorten that to:
dim date1 as datetime
dim date2 as datetime

dim difference as timespan = date2.Subtract( date1)


Which assumes that date2 is after date1.

Hope this helps
Jay

"Dominique Vandensteen" <domi.vds_inser t@tralala_tenfo rce.com> wrote in
message news:OK******** *****@TK2MSFTNG P11.phx.gbl...
something like this?

dim date1 as datetime
dim date2 as datetime

dim ticks1 as long = date1.ticks
dim ticks2 as long = date2.ticks

dim difference as new timespan(math.a bs(ticks1 - ticks2))
Dominique


"Atley" <at*****@hotmai l.com> wrote in message
news:OI******** ******@TK2MSFTN GP12.phx.gbl...
I am trying to get a overall difference on two dates,

I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, Seconds, no problems...

What I cannot seem to figure out is how to get:

2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds.

The hardest part of that, the part I cannot figure out, is the Month
section... all the others are static, defined length components, but

Months
change, are all different...

Help! anyone know how you do this? I am stuck...

Thanks So Much for your Help!

Atley



Nov 20 '05 #13
Sweet...

It works like a charm... you are the best! thanks for the help.


"Dominique Vandensteen" <domi.vds_inser t@tralala_tenfo rce.com> wrote in
message news:uS******** *****@TK2MSFTNG P11.phx.gbl...
aha
you can do somthing like this...

dim date1 as datetime
dim date2 as datetime

dim ticks1 as long = date1.ticks
dim ticks2 as long = date2.ticks
Dim dt As New DateTime(math.a bs(ticks1 - ticks2))
Dim msg As String = "Differnce is:" & vbCrLf & _
"years: " & (dt.Year - 1) & vbCrLf & _
"months: " & (dt.Month - 1) & vbCrLf & _
"days: " & (dt.Day - 1) & vbCrLf & _
"hours: " & dt.Hour & vbCrLf & _
"minutes: " & dt.Minute & vbCrLf & _
"seconds: " & dt.Second

doing -1 for year, month and day:
new datetime(ticks as long) -> gives you a date, not a timespan
and the date is calculated as the number of ticks since 01-01-0001 00:00:00 so doing -1 for day, month and year gives you the remaining time for each
datetime part

isn't that kewl :-)
something not so kewl
try this
date1 = now
date2 = date1.addYear(1 )

result everything 0 except for year... and day (also 1)

tried a little with other "year-add's"
90 -> year=90, day=1
99 -> year=99, day=0

wellwell, bug for small number of add years only?
or am I missing something?

"Atley" <at*****@hotmai l.com> wrote in message
news:eY******** ******@TK2MSFTN GP10.phx.gbl...
Thanks, but i can get the DateDiff several different ways, the problem is with the breakdown into how much time is left as a rundown ie 1 year, 2
months, 1 week, 3 days, 6 hours, 23 minutes, 41 seconds...

"Dominique Vandensteen" <domi.vds_inser t@tralala_tenfo rce.com> wrote in
message news:OK******** *****@TK2MSFTNG P11.phx.gbl...
something like this?

dim date1 as datetime
dim date2 as datetime

dim ticks1 as long = date1.ticks
dim ticks2 as long = date2.ticks

dim difference as new timespan(math.a bs(ticks1 - ticks2))
Dominique


"Atley" <at*****@hotmai l.com> wrote in message
news:OI******** ******@TK2MSFTN GP12.phx.gbl...
> I am trying to get a overall difference on two dates,
>
> I can get the difference in Years, Months, Weeks, Days, Hours,

Minutes, > Seconds, no problems...
>
> What I cannot seem to figure out is how to get:
>
> 2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds.
>
> The hardest part of that, the part I cannot figure out, is the Month
> section... all the others are static, defined length components, but
Months
> change, are all different...
>
> Help! anyone know how you do this? I am stuck...
>
> Thanks So Much for your Help!
>
> Atley
>
>



Nov 20 '05 #14
Ron,

Yea that works, and that is pretty much what I was doing, except you have
the exact same problem with months that I did.
"Ron Allen" <rallen@_nospam _src-us.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Dominique,
How about
Dim difference as TimeSpan = date2.Subtract( date1)
difference = difference.Dura tion() ' correct to positive offset
Now years is difference.Days/365 (ignoring leap year effects 365
days/year)
Days = difference.Days Mod 365
hours, minutes and seconds are directly readable from the timespan.

Ron Allen
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:ep******** ******@TK2MSFTN GP09.phx.gbl...
Dominique,
You know you can shorten that to:
dim date1 as datetime
dim date2 as datetime

dim difference as timespan = date2.Subtract( date1)


Which assumes that date2 is after date1.

Hope this helps
Jay

"Dominique Vandensteen" <domi.vds_inser t@tralala_tenfo rce.com> wrote in
message news:OK******** *****@TK2MSFTNG P11.phx.gbl...
something like this?

dim date1 as datetime
dim date2 as datetime

dim ticks1 as long = date1.ticks
dim ticks2 as long = date2.ticks

dim difference as new timespan(math.a bs(ticks1 - ticks2))
Dominique


"Atley" <at*****@hotmai l.com> wrote in message
news:OI******** ******@TK2MSFTN GP12.phx.gbl...
> I am trying to get a overall difference on two dates,
>
> I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, > Seconds, no problems...
>
> What I cannot seem to figure out is how to get:
>
> 2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds.
>
> The hardest part of that, the part I cannot figure out, is the Month
> section... all the others are static, defined length components, but
Months
> change, are all different...
>
> Help! anyone know how you do this? I am stuck...
>
> Thanks So Much for your Help!
>
> Atley
>
>



Nov 20 '05 #15
What is a year? What is a month?

Peter Seaman
Nov 20 '05 #16
well I used the dateTime and not the TimeSpan just to have an easy way to
find the years, months and days...
"Ron Allen" <rallen@_nospam _src-us.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Dominique,
How about
Dim difference as TimeSpan = date2.Subtract( date1)
difference = difference.Dura tion() ' correct to positive offset
Now years is difference.Days/365 (ignoring leap year effects 365
days/year)
Days = difference.Days Mod 365
hours, minutes and seconds are directly readable from the timespan.

Ron Allen
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:ep******** ******@TK2MSFTN GP09.phx.gbl...
Dominique,
You know you can shorten that to:
dim date1 as datetime
dim date2 as datetime

dim difference as timespan = date2.Subtract( date1)


Which assumes that date2 is after date1.

Hope this helps
Jay

"Dominique Vandensteen" <domi.vds_inser t@tralala_tenfo rce.com> wrote in
message news:OK******** *****@TK2MSFTNG P11.phx.gbl...
something like this?

dim date1 as datetime
dim date2 as datetime

dim ticks1 as long = date1.ticks
dim ticks2 as long = date2.ticks

dim difference as new timespan(math.a bs(ticks1 - ticks2))
Dominique


"Atley" <at*****@hotmai l.com> wrote in message
news:OI******** ******@TK2MSFTN GP12.phx.gbl...
> I am trying to get a overall difference on two dates,
>
> I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, > Seconds, no problems...
>
> What I cannot seem to figure out is how to get:
>
> 2 Years, 3 Months, 1 Week, 3 Days, 14 Hours, 21 Minutes, 33 Seconds.
>
> The hardest part of that, the part I cannot figure out, is the Month
> section... all the others are static, defined length components, but
Months
> change, are all different...
>
> Help! anyone know how you do this? I am stuck...
>
> Thanks So Much for your Help!
>
> Atley
>
>



Nov 20 '05 #17

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

Similar topics

10
1440
by: Sean Ross | last post by:
Here's a breakdown of most of the syntax discussed re: PEP318 using an example from python-dev. There are probably several more (I've added ). The example applies both function decoration and annotation. # .. , competing ways to say the same thing # def foo(self) : "doc string"
0
1386
by: Marco Alting | last post by:
Hi I have a created a cost reporting system which shows a level-breakdown report. There are three levels in the report the lowest level holds the cost items that are entered by the user these records also have an Entry Date. The level above that is a Sum of the lowest level and the top level is the Sum of the second level. I created the solution using three queries in Access. I then use the queries in ASP to generate the report. But now...
0
2148
by: BuddyWork | last post by:
Hello, I want to know if there any good tools out there which will show me a breakdown of the memory allocation in Gen 2 heap, basically a breakdown by object is what I'm looking for. The reason for this is that I eventually get the OutOfMemory exception. I can see the GEN2, GEN1, GEN0 GC kicking in but when run a pariticular code approx 2333
5
2284
by: TN Bella | last post by:
Trying to check if an entry for an date is < 3 years to current date or > 30 days from current date. How can I do this in asp.net....? Do I need to use the customvalidation. Can anyone give me an example? Thanks in advance for the help *** Sent via Devdex http://www.devdex.com *** Don't just participate in USENET...get rewarded for it!
25
4076
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
5
3648
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As New System.Diagnostics.Process 'p.Start(MDEPDirStr & "macrun.exe", sPPTOut) p.Start("C:\WINDOWS\SYSTEM32\CALC.EXE") 'p.Start("C:\WINDOWS\SYSTEM32\macrun.exe", sPPTOut)
9
7451
by: flanagak | last post by:
All, I was wondering if someone could point me in the right direction to decode the following information. I am working on a tool writen in C and one of the items in the file I am decoding is a timestamp in this format. I had started looking at a bitfield structure, but I am wondering if there is a better / more portable solution. Hex Value in the file: 9D AF 79 C0 Binary breakdown: 1001(9) 1101(D) 1010(A) 1111(F) 0111(7) 1001(9)...
3
4602
by: Daron | last post by:
Is it possible to use SQL to take a field, and break it down by denominations? I would like to take a field, and then break this out into the number of bills($100's, $50's, etc) I would need: $469.32 = 4x$100 1x$50 1x$10 1x$5
5
3427
by: Pauley | last post by:
Hello, Please keep in mind when you read this post that I am a total noob when it comes to coding. Coding in ASP On MS Server SQL Database/Table I know this topic has been covered many times and many ways. In fact I've tried to use one version or another of 20 examples with no success. All I am trying to do is determine the timespan between the date a sql record was submitted and the current date.
0
10495
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...
1
10248
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
10032
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
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7573
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
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
5469
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
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2942
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.