|
-
Jan 4th, 2011, 03:01 AM
#1
Thread Starter
New Member
Subtracting 2 Dates
Could someone help me how to subtract 2 Dates?
The format of the Date is "mm/d/yyyy"
Thanks.
-
Jan 4th, 2011, 03:35 AM
#2
Re: Subtracting 2 Dates
Dates do not have a format, only Strings (which includes tooltips for variables in the VB editor) have a format. Are you using Strings for this, or are they actually Dates?
Also, given two dates (perhaps tomorrow and yesterday) and what kind of result are you after?
-
Jan 4th, 2011, 10:49 AM
#3
Lively Member
Re: Subtracting 2 Dates
Declare three double variables.
Convert your string to date.
Convert date to double.
Subtract the two.
Dim D1 as double, D2 as double
Dim DDiff as double
D1 = cdbl(cdate("01/01/2011")
D2 = cdbl(cdate("12/18/2010")
DDiff = D1 - D2
-
Jan 4th, 2011, 10:51 AM
#4
Lively Member
Re: Subtracting 2 Dates
Sorry I forgot the rightmost parenthesis
Dim D1 as double, D2 as double
Dim DDiff as double
D1 = cdbl(cdate("01/01/2011"))
D2 = cdbl(cdate("12/18/2010"))
DDiff = D1 - D2
-
Jan 4th, 2011, 11:37 AM
#5
Re: Subtracting 2 Dates
Why not just use the DateDiff function?
-
Jan 4th, 2011, 01:44 PM
#6
Re: Subtracting 2 Dates
 Originally Posted by baja_yu
Why not just use the DateDiff function?
Why recreate the wheel. This is what I would suggest too
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|