I want to substract a number of month from a specific date.
someone have a easy solution ?
Thanks 7 16243
Developer,
The DataTime structure has an AddMonths method. Give it a negative # of
months to add.
Something like:
DateTime today = DateTime.Today;
today = today.AddMonths (-3);
Will subtract 3 months from today.
Hope this helps
Jay
"developer" <de*******@soge scom.net> wrote in message
news:01******** *************** *****@phx.gbl.. . I want to substract a number of month from a specific date.
someone have a easy solution ? Thanks
developer <de*******@soge scom.net> wrote: I want to substract a number of month from a specific date.
someone have a easy solution ?
I'd suggest creating a new DateTime using the same fields as the
original date, but subtracting the number of months appropriately.
However, you should consider cases like: "What does March 30th -1 month
mean?" and deal with them appropriately.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too -----Original Message----- I want to substract a number of month from a specific
date. someone have a easy solution ? Thanks .
Check out the DateTime class in .Net class library
Jon, However, you should consider cases like: "What does March 30th -1 month mean?" and deal with them appropriately.
The DateTime.AddMon ths with a negative number takes care of that!
However its not symmetrical, March 30th - 1 month, that date +1 month is not
March 30th. Which is always a problem with date arithmetic ;-)
Just a thought
Jay
"Jon Skeet" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@news.microsof t.com... developer <de*******@soge scom.net> wrote: I want to substract a number of month from a specific date.
someone have a easy solution ?
I'd suggest creating a new DateTime using the same fields as the original date, but subtracting the number of months appropriately. However, you should consider cases like: "What does March 30th -1 month mean?" and deal with them appropriately.
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet/ If replying to the group, please do not mail me too
Jon Skeet <sk***@pobox.co m> wrote: developer <de*******@soge scom.net> wrote: I want to substract a number of month from a specific date.
someone have a easy solution ?
I'd suggest creating a new DateTime using the same fields as the original date, but subtracting the number of months appropriately. However, you should consider cases like: "What does March 30th -1 month mean?" and deal with them appropriately.
Look at Jay's answer - ignore this one. Sorry folks :)
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jay B. Harlow [MVP - Outlook] <Ja********@ema il.msn.com> wrote: However, you should consider cases like: "What does March 30th -1 month mean?" and deal with them appropriately. The DateTime.AddMon ths with a negative number takes care of that!
However its not symmetrical, March 30th - 1 month, that date +1 month is not March 30th. Which is always a problem with date arithmetic ;-)
And not the only one.
Over time, I've worked out that the following are just some of the
nightmare worlds it's best not to delve too far into:
o Dates and times, with timezones etc
o Unicode surrogates and the other text oddities (capitalisation being
culture-dependent, etc)
o Telephone numbers (formatting, parsing, generally handling)
Basically anything to do with internationalis ation :)
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Hi Jon Over time, I've worked out that the following are just some of the nightmare worlds it's best not to delve too far into:
o Dates and times, with timezones etc
One thing that has always intrigued me (as an antipodean) is how Americans
(apologies if you are not from the USA) can ignore timezones. After all you
have three across the USA, and many applications must have to deal with
this.
I was suprised the the .NET framework decided only to support the local
computer's timezone. With outsourcing across the world being popular these
days, timezone support is a necessity. Fortunately there are some freeware
classes out there that support timezones on Windows at least. But there are
no user controls to my knowledge that will correctly validate local times.
For instance 2003-03-16 02:30:00 is ambiguous in NZ, as that day we went off
dayliight saving and had two of them. Similarly the time 2003-10-05 02:30:00
will not occur, since we go back on to daylight saving that day.
Around 1993 I built such controls for Informix 4GL under Unix. I thought the
world would have caught up by now!
I think this is an ommission from the framework that should be fixed as soon
as possible.
Regards
Ron This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Adam Knight |
last post by:
I am wanting to create my own calendar asp module.
Are there any functions in vbscript that return the number of days in a
particular month depending on what year it is ??
|
by: jm |
last post by:
I am trying to use datepart to get the real name of the month like
"April" or "APR" not just "4." I could not find it in the
documentation. Sorry. Thank you.
|
by: CBN Media |
last post by:
Hi,
I need to calculate a date which is current date (Now) minus x days.
I looked at DateTime, it has a fairly large number of methods to add
something to a date, but for substracting is just Substract which takes as a
param a TimeSpan.
Am I looking at the wrong method here? It should be as simple as AddDays,
right?!
|
by: james |
last post by:
I have a problem that at first glance seems not that hard to figure out. But, so far, the answer has escaped me. I have an old
database file that has the date(s) stored in it as number of days.
An example is: 36,525 represents 01/01/1900. The starting point date is considered to be :
00/00/0000. I have looked thru Help and used Google and have not really found an answer.
I know that Leap Years need to be accounted for too.
Any...
|
by: Kd |
last post by:
I have the OrderNo set as the following
Right(Format(Date(),"yyyy"),1) & Format(Date(),"mm") &
"-"Format(,"000")+1
This works great until
I get to a new month and need the numbers to reset like the following
example
512-001
Anybody have any thoughts to point me in the right direction,got stuck
with making updates to someone elses created database and getting
frustrated.
| |
by: LimaCharlie |
last post by:
Good Day to Everyone,
Need help!
I have this SQL table w/ fieldname "PayPeriod". Sample value of PayPeriod are SEP06-1, SEP06-2, OCT06-1, OCT06-2... Wherein the first 3 chars is the month, 06 is the year, 1 or 2 is the cutoff where 1 means the 2nd half of the previous month and 2 is the first half of the current month.
Now my questions are:
1.) How can I select these values sorted according to date. Since this is a character data...
|
by: Jef Driesen |
last post by:
How can I convert a date string to a number (e.g. a time_t value or a tm
struct)? I know about the strptime function, but then I have to know the
format string. And that is a problem.
I'm trying to autoformat the contents of text entries in a GUI. For
numbers, I'm converting the text representation to the appropriate type
(using atoi, atof, ...) and converting the result back to text with the
correct format (using sprintf). But this does...
|
by: srusskinyon |
last post by:
I need some help getting unique records from our database! I work for
a small non-profit homeless shelter. We keep track of guest
information as well as what services we have offered for statistical
purposes.
I've been using
Here's the situation:
I have two main tables:
|
by: Brian S. |
last post by:
Hi,
I am trying to calculate the number of DayOfWeek in a month.. for instance..
this month April I want to know how many tuesdays there are in this month,
this year
I try to use
where intDOW = FirstDayOfWeek.Tuesday
dtmFirst = #4/1/2008#, dtmLast = #4/30/2008#
DateDiff(DateInterval.Weekday, dtmFirst, dtmLast, intDOW)
now I would think from reading.. that i would end up with 5, but i am ending
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |