473,721 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Q: comparing date

Hello,
Since I am learning C# now, I might have a simple question, I know my
datarow dr[myDate] keeps datatime and I need to compare it if it is current
date, if not how many days ago? How should I compare date and find how many
day difference?
Thanks,
Jim.

Nov 19 '05 #1
5 1169
Assuming your date in the row is XXX as a DateTime object:

TimeSpan ts = DateTime.Now - XXX;

Now you can look at ts properties such as TotalMinutes, etc.

Amil

"JIM.H." <JI**@discussio ns.microsoft.co m> wrote in message
news:DA******** *************** ***********@mic rosoft.com...
Hello,
Since I am learning C# now, I might have a simple question, I know my
datarow dr[myDate] keeps datatime and I need to compare it if it is current date, if not how many days ago? How should I compare date and find how many day difference?
Thanks,
Jim.

Nov 19 '05 #2
Hi Jim,

You would use the methods of the DateTime object:

http://msdn.microsoft.com/library/de...classtopic.asp

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"JIM.H." <JI**@discussio ns.microsoft.co m> wrote in message
news:DA******** *************** ***********@mic rosoft.com...
Hello,
Since I am learning C# now, I might have a simple question, I know my
datarow dr[myDate] keeps datatime and I need to compare it if it is
current
date, if not how many days ago? How should I compare date and find how
many
day difference?
Thanks,
Jim.

Nov 19 '05 #3
Thanks for the reply.
DateTime sDate=System.Co nvert.ToDateTim e(dr["myDate"]);

TimeSpan ts = DateTime.Now - sDate;
int tHours=ts.Hours ;
int tDays=ts.Days;

This is working fine to see discrepancy in hours. Now I only need to compare
date part of DateTime for both dr["myDate"] and DateTime.Now. how should I do
this?
Thanks,
Jim.
"Amil" wrote:
Assuming your date in the row is XXX as a DateTime object:

TimeSpan ts = DateTime.Now - XXX;

Now you can look at ts properties such as TotalMinutes, etc.

Amil

"JIM.H." <JI**@discussio ns.microsoft.co m> wrote in message
news:DA******** *************** ***********@mic rosoft.com...
Hello,
Since I am learning C# now, I might have a simple question, I know my
datarow dr[myDate] keeps datatime and I need to compare it if it is

current
date, if not how many days ago? How should I compare date and find how

many
day difference?
Thanks,
Jim.


Nov 19 '05 #4
DateTime sDate=System.Co nvert.ToDateTim e(dr["myDateTime "]);

if (sDate.Date < DateTime.Now.Da te)
{
debug= "Warning: old date!";
}

do you see any problem with this comparision, it seems it is working?
Thanks,
Jim.

"Kevin Spencer" wrote:
Hi Jim,

You would use the methods of the DateTime object:

http://msdn.microsoft.com/library/de...classtopic.asp

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"JIM.H." <JI**@discussio ns.microsoft.co m> wrote in message
news:DA******** *************** ***********@mic rosoft.com...
Hello,
Since I am learning C# now, I might have a simple question, I know my
datarow dr[myDate] keeps datatime and I need to compare it if it is
current
date, if not how many days ago? How should I compare date and find how
many
day difference?
Thanks,
Jim.


Nov 19 '05 #5
Jim:

DateTime.Now gives you the current date and time, and DateTime has a
subtraction method defined (which returns a TimeSpan, and a TimeSpan
has a Days property). There are some examples in the docs:
http://msdn.microsoft.com/library/de...tracttopic.asp
HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 8 Apr 2005 12:45:02 -0700, JIM.H.
<JI**@discussio ns.microsoft.co m> wrote:
Hello,
Since I am learning C# now, I might have a simple question, I know my
datarow dr[myDate] keeps datatime and I need to compare it if it is current
date, if not how many days ago? How should I compare date and find how many
day difference?
Thanks,
Jim.


Nov 19 '05 #6

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

Similar topics

21
11081
by: Javier | last post by:
Hi I´ve a routine that will read date and times in a vector of strings ie: 30/02/2005 19:20 In some moment I´ll need to check if there are in vector a date like current date with a time >= current time and <= (current time + n minutes)
2
3343
by: Manny Chohan | last post by:
Hi, i have two datetime values in format 11/22/04 9:00 AM and 11/22/04 9:30 AM. How can i compare dates .net c# or if there is any other way such as Javascript. Thanks Manny
0
1406
by: babz | last post by:
Hi I am facing one peculiar problem. When I tried to compare control value with the current date, it is not validating. All I am doing is in the Page Load I have a code cmp1.ValueToCompare = System.DateTime.Today.ToString("MM/dd/yyyy"); and my validator code is
5
3805
by: Kermit Piper | last post by:
Hello, I am comparing two date values, one from a database and one that has been converted from a hard-coded string into an actual Date type. So far so good. The problem I'm having is that one of the values comes from the database, and for existing values it works fine, but if the date doesn't exist (which will always be the condition when the user first enters into the form) I am adding logic to my javascript like: if (dbDate <...
2
1402
by: Bob | last post by:
Hi, I have a wrong result when testing today against a date fetched from a table in excel. The value in excel is: 14/12/2006 (european format). When today is after that value in excel, the message "time is over" must appear, otherwise nothing. My problem is that the message appear already when today = that value. Any idea why?
1
1807
by: gderosa | last post by:
Hey everyone...I need to create a job which occurs once monthly that is based on a stored procedure that contains as a rough example: CREATE PROCEDURE CompareDate @CurrentDate datetime AS SELECT * FROM Contracts WHERE EndDate LIKE (CURRENT SERVER DATE) GO
1
1225
by: cmrhema | last post by:
Hi, I have designed an employee portal. The moment the user logs in and logs out the current datetime will be stored. Before the user logs out I should ensure whether he/she has entered the work done form for that day. I wrote select count(*) from workdone where work_date_time=getdate() If there are any rows that means he/she has filled up the form else not filled. But the query is comparing the date as well as time.
2
2714
by: akshaycjoshi | last post by:
Hi, I am developing one application which requires me to compare date.The dataabse being MS access 2003. When i execute the query in c# it does not show any record ,the date although matches with the date in database. Where is the problem ? The quey executed is select * from finetable where fine_date=#1/9/2008 6:46:36 PM# (The above date is entered by dateTimePicker)
3
3195
by: vinpa | last post by:
Hello, I wish to have the user enter a date range (i.e. 01/01/2009 ---> 12/31/2009) to retrieve data to populate part of my report, and then populate another column with the same date range, but from, say, a year earlier. This will help determine sales from year to year. Example: Order # Account # Product ID # Sold '07 # Sold '08 Profit '07 Profit '08 01 12842 129 200 193 ...
0
8730
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,...
0
9367
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...
1
9131
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,...
0
8007
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
6669
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
4484
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
4753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3189
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
3
2130
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.