473,386 Members | 1,698 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,386 software developers and data experts.

how to find first day among given dates

I have selected some list of valid dates to a label.
now i need to find first day among the given dates from label contrl

i got dates from calender control by clicking for entire week..


that is i have dates from sunday to saturday and I have to find which date is sunday......
Feb 12 '09 #1
3 2337
PRR
750 Expert 512MB
try this
Expand|Select|Wrap|Line Numbers
  1. DateTime now = DateTime.Now;
  2.             List<DateTime> allDates = new List<DateTime>();
  3.             allDates.Add(now);
  4.             allDates.Add(now.Subtract(new TimeSpan(0,0,20,20,0)));
  5.  
  6.             allDates.Sort();
  7.  
Feb 12 '09 #2
tlhintoq
3,525 Expert 2GB
This would be a good example of not planning ahead. You coded, before you planned. Two words: "Software engineer" - meaning to engineer the software. A person wouldn't build a building by nailing together a bunch of wood, then two days in start thinking about how they are going to accommodate a door and window. Same in this field.

Enough with the scolding...
Based on your question I'm guessing you did exactly what you said: You added dates as text into a label. Now you are stuck because you don't have any dates to work with, only text. It is possible to convert text back into DateTime (do some reading about TryParse), but it would be better to re-engineer what your application is doing.
Tip 1: Never throw something away until you are sure you are done with it.
Tip 2: Remember to keep your data, and your user interface seperate in your mind.

In this case, as you take in dates from your Calendar control be sure to add them to a List<> or Array of DateType objects just as DeepBlue has indicated. This is the data you will actually use. If you also want to add them to a text box, list control, label or some other UI for your user that's cool too, but the UI is just for the user and not for your program to think with.

Now that you have a list/array of DateTime objects you can work through them for whatever purpose you want. Use a 'for' loop to check each item in the list/array. Is it a Sunday date? Is it after 2 pm? Is it before or after your target date? and so on.
Feb 12 '09 #3
PRR
750 Expert 512MB
extremely good "expert" advice tlhintoq... thanks a lot ...
pchaitanya, do remember as tlhintoq pointed out "the UI is just for the user and not for your program to think with ".. it will be better to keep selected dates as date in some list for further processing ....
Feb 13 '09 #4

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

Similar topics

9
by: Simon Harris | last post by:
Hi All, Ok - I'll confess from the start, this is more about application logic that ASP, being an ASP programmer, I guessed you people might be able to help! :) I have built a room bookings...
0
by: aredo3604gif | last post by:
The user can dynamically enter and change the rule connection between objects. The rule is a "<" and so given two objects: a < b simply means that b < a can't be set, also it must be a != b. And...
1
by: aredo3604gif | last post by:
On Sun, 10 Apr 2005 19:46:32 GMT, aredo3604gif@yahoo.com wrote: >The user can dynamically enter and change the rule connection between >objects. The rule is a "<" and so given two objects: >a <...
17
by: Justin Emlay | last post by:
I'm hopping someone can help me out on a payroll project I need to implement. To start we are dealing with payroll periods. So we are dealing with an exact 10 days (Monday - Friday, 2 weeks). ...
18
by: dfetrow410 | last post by:
Anyone have some code that will do this? Dave
67
by: PC Datasheet | last post by:
Transaction data is given with date ranges: Beginning End 4/1/06 4/4/06 4/7/06 4/11/06 4/14/06 4/17/06 4/18/06 4/21/06 426/06 ...
44
by: user | last post by:
Hi, Let's say I have 2 dates in the b/m format: Date 1 and date 2 How do I check whether Date2 is later than Date 1? Date1. 21-Nov-2006 09:00:00 PM
4
by: perryclisbee via AccessMonster.com | last post by:
I have dates of service for several people that range all over each month. ie: patient had dates of service of: 7/3/2006, 7/24/2006 and 7/25/2006. I need to create a new field via a query that...
5
by: jm.suresh | last post by:
Hi I have three objects, all of them are instances of classes derived from a base class. Now, given one of the instance, I want to find the closest relative of the other two. How can I do this? ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.