473,405 Members | 2,262 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,405 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 882

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

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:...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
Oralloy
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,...
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...
0
tracyyun
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...
0
isladogs
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 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.