I need to compare dates. But this way:
I get a date from database.
I need to understand if this date is newer then "6 months" or not.
What I need is get the current date,
calculate the date 6 months ago,
compare "the date from DB" & "the date 6 months ago from now"
show the result.
How will I do that using DateTime or TimeSpan classes? 5 1411
The different Add-methods on the DateTime class accepts negative
values. To subtract 6 months of the current date, you would do like this
DateTime today = DateTime.Now;
DateTime then = today.AddMonths(-6);
The variable 'then' will now contain the date you are looking for.
HTH,
//Andreas
"Dinçer" <dincer80"at"yahoo.com> skrev i meddelandet
news:%2****************@TK2MSFTNGP09.phx.gbl... I need to compare dates. But this way:
I get a date from database. I need to understand if this date is newer then "6 months" or not.
What I need is get the current date, calculate the date 6 months ago, compare "the date from DB" & "the date 6 months ago from now" show the result.
How will I do that using DateTime or TimeSpan classes?
Thank you.
One last question:
The type of the date I get from DB is String.
How can I convert it to DateTime. (So that I can make the comparison)
DateTime constructer has no String argument. How will I do this?
"Andreas Håkansson" <andy.h (at) telia.com> wrote in message
news:uK**************@TK2MSFTNGP11.phx.gbl... The different Add-methods on the DateTime class accepts negative values. To subtract 6 months of the current date, you would do like this
DateTime today = DateTime.Now; DateTime then = today.AddMonths(-6);
The variable 'then' will now contain the date you are looking for.
HTH,
//Andreas
"Dinçer" <dincer80"at"yahoo.com> skrev i meddelandet news:%2****************@TK2MSFTNGP09.phx.gbl... I need to compare dates. But this way:
I get a date from database. I need to understand if this date is newer then "6 months" or not.
What I need is get the current date, calculate the date 6 months ago, compare "the date from DB" & "the date 6 months ago from now" show the result.
How will I do that using DateTime or TimeSpan classes?
Dinçer,
The DateTime structure has two static members which should be of
intresst to you. They are DateTime.Parse() and DateTime.ParseExact(),
and I recommend you read the documentation for them.
HTH,
//Andreas
"Dinçer" <dincer80"at"yahoo.com> skrev i meddelandet
news:Of*************@TK2MSFTNGP12.phx.gbl... Thank you. One last question:
The type of the date I get from DB is String. How can I convert it to DateTime. (So that I can make the comparison)
DateTime constructer has no String argument. How will I do this?
"Andreas Håkansson" <andy.h (at) telia.com> wrote in message news:uK**************@TK2MSFTNGP11.phx.gbl... The different Add-methods on the DateTime class accepts negative values. To subtract 6 months of the current date, you would do like this
DateTime today = DateTime.Now; DateTime then = today.AddMonths(-6);
The variable 'then' will now contain the date you are looking for.
HTH,
//Andreas
"Dinçer" <dincer80"at"yahoo.com> skrev i meddelandet news:%2****************@TK2MSFTNGP09.phx.gbl... I need to compare dates. But this way:
I get a date from database. I need to understand if this date is newer then "6 months" or not.
What I need is get the current date, calculate the date 6 months ago, compare "the date from DB" & "the date 6 months ago from now" show the result.
How will I do that using DateTime or TimeSpan classes?
OK.
Thank you..
"Andreas Håkansson" <andy.h (at) telia.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... Dinçer,
The DateTime structure has two static members which should be of intresst to you. They are DateTime.Parse() and DateTime.ParseExact(), and I recommend you read the documentation for them.
HTH,
//Andreas
"Dinçer" <dincer80"at"yahoo.com> skrev i meddelandet news:Of*************@TK2MSFTNGP12.phx.gbl... Thank you. One last question:
The type of the date I get from DB is String. How can I convert it to DateTime. (So that I can make the comparison)
DateTime constructer has no String argument. How will I do this?
"Andreas Håkansson" <andy.h (at) telia.com> wrote in message news:uK**************@TK2MSFTNGP11.phx.gbl... The different Add-methods on the DateTime class accepts negative values. To subtract 6 months of the current date, you would do like
this DateTime today = DateTime.Now; DateTime then = today.AddMonths(-6);
The variable 'then' will now contain the date you are looking for.
HTH,
//Andreas
"Dinçer" <dincer80"at"yahoo.com> skrev i meddelandet news:%2****************@TK2MSFTNGP09.phx.gbl... > I need to compare dates. But this way: > > I get a date from database. > I need to understand if this date is newer then "6 months" or not. > > What I need is get the current date, > calculate the date 6 months ago, > compare "the date from DB" & "the date 6 months ago from now" > show the result. > > How will I do that using DateTime or TimeSpan classes? > >
<"Dinçer" <dincer80"at"yahoo.com>> wrote: The type of the date I get from DB is String.
Along with the other answers you've received, I have to at least
suggest that if you have any control over the database whatsoever, then
you change the type of the column to be a date type. It will make your
life *far* easier. I realise you may not have control over the
database, but if you do, it's definitely something to think about
changing.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: js |
last post by:
Hi all,
I currently encounter a problem and it is urgent to me.
After calling the MsgBox.Show(), the message box is shown with non-modal
mode, what is the possible reason??? This only happen...
|
by: Stefan Bauer |
last post by:
Hi NG,
we've got a very urgent problem... :(
We are importing data with the LOAD utility. The input DATE field data
is in the format DDMMYYYY (for days) and MMYYYY (for months).
The target...
|
by: Mike |
last post by:
Hello,
I have a few rather urgent questions that I hope someone can help with (I
need to figure this out prior to a meeting tomorrow.) First, a bit of
background: The company I work for is...
|
by: Dinçer |
last post by:
I need to compare dates. But this way:
I get a date from database.
I need to understand if this date is newer then "6 months" or not.
What I need is get the current date,
calculate the date 6...
|
by: |
last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I
keep getting the following error:-
Error In:...
| |
by: varkey.mathew |
last post by:
Dear all,
Bear with me, a poor newbie(atleast in AD)..
I have to authenticate a user ID and password for a user as a valid
Active Directory user or not. I have created the IsAuthenticated...
|
by: viki.sanjeeva |
last post by:
Hi,
There is a date field in JSP form where user will enter date in
dd-mm-yyyy format. Now before saving into DB2, I want to validate the
date format against dd-mm-yyyy format and then save into...
|
by: rajesh.us.it.recruiter |
last post by:
Hi Guys/Partners,
We have a URGENT Requirement for Perl Programmer with H1 visa in
India/US for one of our prestigious Client. Location : New Jersey
Requirements :
Should be very strong in...
|
by: imran haq |
last post by:
Hi All,
I have 3 rather Long Questions that are causing alot of trouble:
I would appreciate all the help i can get and tried to use A post sent to atli in the past but it did not help...
!) I...
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |