Solved

DateTime Compare Function

Posted on 2008-06-20
4
1,684 Views
Last Modified: 2013-12-16
hi,
I have the following function that returns always 1 no matter what:
for (i = 0; i <= Count - 2; i++) {
            for (j = 0; j <= 6; j++) {                
                 strWeekDay = DateTime.Today.AddDays(DateTime.Compare(DateTime.Today.AddDays(j), StartTime)).ToString("dddd");
...etc
  }
}
When I run it (Today) it always return Saturday!. I tried the compare function on its own and namtter what I enter for the StartTime (DateTime Variable) it always returns 1

I am trying to get the difference between the two sates in Days of the Week (Sunday, Monday...)

any idea how to fix it?
I am using ASP.NET - C#
0
Comment
Question by:smaguire
  • 2
4 Comments
 
LVL 25

Expert Comment

by:apeter
ID: 21834270
Can't you use DateTime.Compare() ?
0
 

Author Comment

by:smaguire
ID: 21834288
thats what I am using
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 21834507
are you trying to calculate the Day of Week?
There is a property for this:

int dow = (int)(yourDateTime.DayOfWeek);

also, when comparing, consider you are comparing date and time, this can give you unexpected results, if you want to compare just dates, do something like this:

datetime1.Date.Compare(datetime2.Date)
 
0
 

Author Closing Comment

by:smaguire
ID: 31469301
Thanks
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question