?
Solved

DateTime Compare Function

Posted on 2008-06-20
4
Medium Priority
?
1,692 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

752 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