[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

DateTime Compare Function

Posted on 2008-06-20
4
Medium Priority
?
1,696 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

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…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

656 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