Solved

DateTime Compare Function

Posted on 2008-06-20
4
1,678 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
Comment Utility
Can't you use DateTime.Compare() ?
0
 

Author Comment

by:smaguire
Comment Utility
thats what I am using
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now