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 1432
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?
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?
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?
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? > >
<"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 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 in the VB project,
works fine in C# project.
SystemModal and ApplicationModal MsgBoxStyle were all tried and there
was no help.
|
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
|
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,...
|
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.
|
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...
| |
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
|
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.
|
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
|
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
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
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 we have to send another system
| |
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...
| |