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

Urgent date question

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?
Nov 16 '05 #1
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?

Nov 16 '05 #2
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?


Nov 16 '05 #3
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?



Nov 16 '05 #4
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?
>
>



Nov 16 '05 #5
<"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
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
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...
9
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...
8
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...
5
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...
16
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:...
6
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...
1
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...
1
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...
1
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...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
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...
0
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...
0
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...
1
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)...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
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
0
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...

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.