473,320 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to get mindate ?

12
Hi Guys,
I've been trying to get the Mindate from the array. But the output I've got was all dates in the array. I know there is somthing missing but I couldn't figure it out. Please help.
Thanks
aboon.

Expand|Select|Wrap|Line Numbers
  1. DateTime dtMinDate = new DateTime();
  2.             string strDateFrom = emp.DateFrom; 
  3.             string [] arrDateFrom = strDateFrom.Split((new char[]{','})); 
  4.             if (arrDateFrom != null && arrDateFrom.Length > 0)            
  5.             {   
  6.                 for (int j = 0; j < arrDateFrom.Length; j++)                
  7.                 {    
  8.         dtMinDate  = Convert.ToDateTime(arrDateFrom.GetValue(j));
  9.                  }
  10.                  Response.Write("Minimum Date: " + dtMinDate.Date.ToString());
  11.              }
  12.  
Sep 15 '08 #1
5 1588
Plater
7,872 Expert 4TB
All yo uare doing is printing out the dates in the array.
You are not doing any logic on it to determine which date is smallest at all.
Perhaps you should trying doing some comparison logic on it?
Sep 15 '08 #2
balabaster
797 Expert 512MB
Ah, I came across a scenario where I wanted to provide the max from a param array of doubles earlier and I was half way through coding a loop when I thought of a couple of other nifty ways of doing it that would work here too that didn't require me looping through the array...and is also much less code.

The first is with LINQ
Expand|Select|Wrap|Line Numbers
  1. Dim qry = From n In MyParamArray Order By n Select n
  2. Dim min = qry.First
  3. Dim max = qry.Last
The second is just using the plain old sort mechanism from the Array construct:
Expand|Select|Wrap|Line Numbers
  1. Dim Sorted = Array.Sort(MyParamArray)
  2. Dim min = Sorted(0)
  3. Dim max = Sorted(Sorted.Length - 1)
I imagine the same two concepts could be applied to dates without any fuss.
Sep 15 '08 #3
aboon
12
That's the part I'm not sure how to do. I haved tried the code below, the out put of mindate was the DateTime.MinDate not the mindate in the array. Would you plaease give show me some example.

Expand|Select|Wrap|Line Numbers
  1. DateTime dtMinDate = new DateTime();
  2. string strDateFrom = empWH.DateFrom;
  3. string [] arrDateFrom = strDateFrom.Split((new char[]{','})); 
  4.  
  5. if (arrDateFrom != null && arrDateFrom.Length > 0)            
  6. {   
  7.    for (int j = 0; j < arrDateFrom.Length; ++j)
  8.   {
  9.       DateTime dtFrom1 = Convert.ToDateTime(arrDateFrom.GetValue(j));
  10.       for (int k = j + 1; k < arrDateFrom.Length; ++k)
  11.       {
  12.           DateTime dtFrom2 = Convert.ToDateTime(arrDateFrom.GetValue(k));
  13.           int intFrom = DateTime.Compare(dtFrom1, dtFrom2);
  14.           if (intFrom > 0)
  15.           {
  16.               dtMinDate = dtFrom2;
  17.               break;
  18.           }
  19.       }
  20.   }
  21. }
  22. Response.Write("Minimum Date: " + dtMinDate.Date.ToString());
Sep 15 '08 #4
Curtis Rutland
3,256 Expert 2GB
balabaster has a good suggestion. If you have an array of DateTimes, you should be able to .Sort() the array no problem. Then, depending on how the sort algorithm is set up, it will either be the first or last value in the array. Most likely the first.
Sep 15 '08 #5
PRR
750 Expert 512MB
Try checking out
using System.Collections;
using System.Collections.Generic;

They are better ways to store up info....

Expand|Select|Wrap|Line Numbers
  1. List<DateTime> now = new List<DateTime>();
  2.  
  3. now.Add(DateTime.Now);
  4.             now.Add(DateTime.Now.Subtract(new TimeSpan(1,0,0,0)));
  5.             now.Add(DateTime.Now.AddDays(1));
  6.  
  7.             now.Sort();
  8. //sorted...
  9.  
  10.             now.Reverse();
  11. // now in reverse order..
  12.  
  13.  
Sep 16 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jon Maz | last post by:
Hi, I have a table (SQL Server 2000) with several date columns in it, all of which are individually NULLable, but in any one row, not all the dates can be NULL. I want a query which ORDERs BY...
11
by: Hennie de Nooijer | last post by:
hi thank you for this solution Hugo (dutch?) and it's very handy, thank you but my issue is that we created dozens of views with my function. This functions returns an integer of a date. This...
0
by: Rob | last post by:
Access Gurus, This script was used to view the reports on the web by choosing a date on or before the current day.Recently it stopped working and i am not able to figure where the problem is. ...
1
by: Rob | last post by:
Access Gurus, This script was used to view the reports on the web by choosing a date on or before the current day.Recently it stopped working and i am not able to figure where the problem is. ...
5
by: Tomer | last post by:
I Created 3 Properties to my Control Mindate(retuns date) MaxDate ( return date ) and a CustomList Property (allDates,Uptodate...) when i choose from the list allDates for example the Mindate and...
1
by: daz_oldham | last post by:
C# 2.0 Hi everyone I want to set a date range on my calendar control, but cannot figure out how to do it. this.clnSelectDate.MinDate Is not a valid option for me, and I would like to be...
1
by: ml41782 | last post by:
I have a personal web server that imports from my weather station. The data is already in XML format. I created my xsl and it displays the data on the web page very nicely. I have been...
0
by: MarcoDieleman | last post by:
Hello you all, I have this code that is written in MS Transact-SQL and I need to convert it to work with Oracle. Can anyone please help??? I need the code for a VBscript project. Thanks! ...
1
by: aboon | last post by:
I have a list of startdates and enddates in the database somewhere. I want to find minDate from the list of startdates and maxDate from the list of enddates. Would anyone tell me how to do that. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.