473,657 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to find first day among given dates

13 New Member
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 2346
PRR
750 Recognized Expert Contributor
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 Recognized Expert Specialist
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 Recognized Expert Contributor
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
1905
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 system, based on ASP/SQL Server. Bookings are stored in a table, which holds start date+time and End date+time, amougst other info. Bookings can run from 8:30 - midnight, and are always made in 30 min blocks (e.g. 14:30 - 15:30 etc)
0
352
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 with three objects a < b , b < c means a < c I studied Quick Union Find algorithms a bit and if I understood them correctly, once the user gives the input setting the rules/connection between objects, the algorithm will give as output the result...
1
2636
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 < b simply means that b < a can't be set, also it must be a != b. >And with three objects a < b , b < c means a < c > >I studied Quick Union Find algorithms a bit and if I understood them >correctly, once the user gives the input setting the...
17
3012
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). I have a dataset as follows (1 week to keep it short): Employee 1 - Date 1 Employee 1 - Date 2
18
38226
by: dfetrow410 | last post by:
Anyone have some code that will do this? Dave
67
7682
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 4/30/06 I am looking for suggestions on how to find the date ranges where there were no transactions.
44
10182
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
39323
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 will convert each of the records of these service dates to the first date of that month, with results showing: 7/1/2006, 7/1/2006, 7/1/2006. How would you place an expression on a query that will convert any given date to the first day of the month...
5
2593
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? This is how I implemented; I guess there must be elegant way to do this... def find_closest_relative(a,b,c): c1 = b.__class__ c2 = b.__class__
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8837
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7347
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6175
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.