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

Subtract a date from a date

54
I'm using vb.net 2008 and sqlserver 2008 and I want subtract a date from a specified date. Example:

I want to subtract Commencedate from Today's Date but when I used datediff it gave me (argument "interval" is not a valid date).

When I used year(Commencedate)-year(now), it worked but the month did not get subtracted. Can someone help me out?

Thank in advance,

Ben
Feb 12 '10 #1

✓ answered by tlhintoq

As long as your dates are DateTime objects you don't need to specify the years. Just subtract one from the other.

Expand|Select|Wrap|Line Numbers
  1. // C#
  2. DateTime start = new DateTime.TryParse("December 25, 1979");
  3. DateTime end = DateTime.Now;
  4. Timespan TheDiff = end - start;

2 2538
CroCrew
564 Expert 512MB
Hello Benniit,

Can we get you to post your code so that we can provide you with the best solution to your question? It makes it easier to show you when we can inject the solution into your code.

Happy Coding,
CroCrew~
Feb 12 '10 #2
tlhintoq
3,525 Expert 2GB
As long as your dates are DateTime objects you don't need to specify the years. Just subtract one from the other.

Expand|Select|Wrap|Line Numbers
  1. // C#
  2. DateTime start = new DateTime.TryParse("December 25, 1979");
  3. DateTime end = DateTime.Now;
  4. Timespan TheDiff = end - start;
Feb 12 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: dlx_son | last post by:
Here is the code so far <form name="thisform"> <h3>Enter time to add to or subtract from:</h3> (If not entered, current time will be used)<br> Day: <input name="d1" alt="Day of month"...
7
by: Jimbo | last post by:
Anyone know how I can subtract 12 months from the current date?
10
by: Trapulo | last post by:
Why Now.Date.Subtract(New Date(2000, 1, 1)).Days returns 731529?? It is a too big value a think! I aspect something as 1030-1100....
3
by: S. van Beek | last post by:
Dear reader, With DatePart() you can subtract the year or the week from a date field with: DatePart("yyyy";) for the year
5
by: cvisal | last post by:
Hi all Im working on productivity calculations (Time calculations) and need some help in coding. Database Tool:MS-Access 2003. The general operator punch-in time is 5:30 AM and the punch-out...
4
by: meltedown | last post by:
I can't see what I'm doing wrong. I'm subtracting 60*60*24 from a unix time stamp and the result is 23 hours earlier, not 24. Start with a unix time stamp: $unixtime=1144018006; convert it to...
8
by: Remington | last post by:
I am using windows 2000pro with access 2000. I am trying to make a database for our HR department, that would allow our HR Director to type in an employee's ID number into a form and then select...
3
by: Arne Gemsa | last post by:
Hi, I want to get a starttime. To get this I have to subtract the runtime from a unit e.g. 08:40:15 from a date e.g. 2007-03-29 16:48:30. So the starttime is 2007-03-29 08:08:15. Is there any...
2
by: jld730 | last post by:
Hello All, I am very new to Python and Oracle, and I have a question for you all. How do you add/subtract minutes to a date? Is this possible? I need to add/subtract 30 minutes (or 60, or 90,...
10
by: dan | last post by:
Am i breaking any rules when I loop dates like // Determine Memorial Day intFlag = 0; memDayHol = new Date (currentYear, 4, 31); while (intFlag == 0) { if (memDayHol.getDay() == 1) {intFlag...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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...
0
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...
0
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...

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.