473,795 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1030

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"ya hoo.com> skrev i meddelandet
news:%2******** ********@TK2MSF TNGP09.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******** ******@TK2MSFTN GP11.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"ya hoo.com> skrev i meddelandet
news:%2******** ********@TK2MSF TNGP09.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.ParseE xact(),
and I recommend you read the documentation for them.

HTH,

//Andreas

"Dinçer" <dincer80"at"ya hoo.com> skrev i meddelandet
news:Of******** *****@TK2MSFTNG P12.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******** ******@TK2MSFTN GP11.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"ya hoo.com> skrev i meddelandet
news:%2******** ********@TK2MSF TNGP09.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******** ********@TK2MSF TNGP09.phx.gbl. ..
Dinçer,

The DateTime structure has two static members which should be of
intresst to you. They are DateTime.Parse( ) and DateTime.ParseE xact(),
and I recommend you read the documentation for them.

HTH,

//Andreas

"Dinçer" <dincer80"at"ya hoo.com> skrev i meddelandet
news:Of******** *****@TK2MSFTNG P12.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******** ******@TK2MSFTN GP11.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"ya hoo.com> skrev i meddelandet
news:%2******** ********@TK2MSF TNGP09.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"ya hoo.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.co m>
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
5998
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 in the VB project, works fine in C# project. SystemModal and ApplicationModal MsgBoxStyle were all tried and there was no help.
9
4319
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 data format is european DD.MM.YYYY (for days) and 01.MM.YYYY (for months). The input format is not recognizable as a DATE input to a DB2 LOAD for
8
5266
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 developing a web-based application, one part of which involves allowing the user the ability to page through transaction "history" information. The _summary_ history table will have the following fields: ServiceName, Date, User-Ref1, User-Ref2,...
5
1433
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 months ago, compare "the date from DB" & "the date 6 months ago from now" show the result.
16
2969
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: http://www.mywebsite.org/WebResource.axd?d=5WvLfhnJp5Lc8WhQSD4gdA2&t=632614619884218750 -------------------------------------------------------------------------------- System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed. at...
6
2469
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 function exactly as outlined in the below link. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT02.asp
1
4207
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 DB2. I've tried reading SimpeDateFormat and other date format classes, but couldn't understand. It will be great if somebody tell the following with code.
1
2133
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 Perl Should be strong in SQL, Unix, C++ Should have some knowledge in RDBMS
1
1258
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 retrieve a particular column on a specific date ex= "SELECT columnname from tablename where columnname='$dt'"; $sd=mysql_query($selectdate); $sdr=mysql_num_rows($sd); if($sdr > 0) { echo "Records found" }
0
1736
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 have an events table, within the events table I have 7 columns, Alias varchar (30) Progress int(1) Val double Stamp timestamp
0
10448
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, 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...
0
10217
jinu1996
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...
0
9046
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7544
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 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...
0
5440
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...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
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 we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2922
bsmnconsultancy
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...

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.