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 1013
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: runway27 |
last post by:
I have a table in mysql which i have defined as date and the values that are inserted have the following format for example : 2007-10-30 08:02:40
My requirement is to run a select query to...
|
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: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |