473,804 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DateTime short formatted range lookup

Hello,

I'm trying to figure out a method to look up by a range of dates,
entries in a database. The format of the date in the database is "M\D
\yyyy HH:MM:SS".

What i need to do is take the dates that are in the database
(formatted as above), isolate the date (which is in short format) and
compare it to the short formatted date in a datetimepicker.

How can I take a string and format it as a short date?

How can I compare two short dates, to find if the date falls in the
date range? (isolate each part of the date? is there an actual
function that handles this?)
Any help is greatly appreciated,

Matt

Aug 7 '07 #1
3 2232
Matt Brown - identify wrote:
Hello,

I'm trying to figure out a method to look up by a range of dates,
entries in a database. The format of the date in the database is "M\D
\yyyy HH:MM:SS".
Why are you storing the date as a string in the database? Store it as a
date.
What i need to do is take the dates that are in the database
(formatted as above), isolate the date (which is in short format) and
compare it to the short formatted date in a datetimepicker.

How can I take a string and format it as a short date?
You can't. You first have to convert it to a date, then you can format
it to a string.
How can I compare two short dates, to find if the date falls in the
date range?
You can't. The date format that you are using is not comparable.
(isolate each part of the date? is there an actual
function that handles this?)
The DateTime structure has a Date property that gives you the date part,
i.e. a DateTime value where the time part is 00:00:00.

However, you don't need any of that for what you are doing. Get the date
from the DateTimePicker, and calculate the starting and ending time of
the interval. Then you can easily select the records from the database
where the date is between them.

That is of course if you change the database so that you store the date
as a date, so that it's possible to compare it to anything at all.

--
Göran Andersson
_____
http://www.guffa.com
Aug 8 '07 #2
On Aug 7, 9:43 pm, Göran Andersson <gu...@guffa.co mwrote:
>
Why are you storing the date as a string in the database? Store it as a
date.

It is stored as datetime.
>
You can't. You first have to convert it to a date, then you can format
it to a string.
I don't need to convert it.
>
You can't. The date format that you are using is not comparable.
Are they both short dates?
1) M/D/yyyy
2) M/D/yyyy HH:MM:SS

If not, there must be a conversion?
>
The DateTime structure has a Date property that gives you the date part,
i.e. a DateTime value where the time part is 00:00:00.

However, you don't need any of that for what you are doing. Get the date
from the DateTimePicker, and calculate the starting and ending time of
the interval. Then you can easily select the records from the database
where the date is between them.

That is of course if you change the database so that you store the date
as a date, so that it's possible to compare it to anything at all.

Can you give me some syntax or examples? for instance, if the date
time pickers are called dateStart and dateEnd, how would i compare the
two?

I'm guessing that the variable that I'm setting the date value out of
the datebase to, needs to be a datetime?

I'm new at this.
Thanks!

Matt
Aug 8 '07 #3
Matt Brown - identify wrote:
On Aug 7, 9:43 pm, Göran Andersson <gu...@guffa.co mwrote:
>Why are you storing the date as a string in the database? Store it as a
date.


It is stored as datetime.
You said that the date had a specific format, that's why I assumed that
it was a string. A datetime value doesn't have a format.
>You can't. You first have to convert it to a date, then you can format
it to a string.
I don't need to convert it.
>You can't. The date format that you are using is not comparable.

Are they both short dates?
1) M/D/yyyy
2) M/D/yyyy HH:MM:SS
These are date format, not dates. DateTime values doesn't have a format,
they only get a format when you convert them to strings. A DateTime
value always contains a date and a time component.
If not, there must be a conversion?
If you convert the dates into strings in that format, you can't compare
them.
>The DateTime structure has a Date property that gives you the date part,
i.e. a DateTime value where the time part is 00:00:00.

However, you don't need any of that for what you are doing. Get the date
from the DateTimePicker, and calculate the starting and ending time of
the interval. Then you can easily select the records from the database
where the date is between them.

That is of course if you change the database so that you store the date
as a date, so that it's possible to compare it to anything at all.


Can you give me some syntax or examples? for instance, if the date
time pickers are called dateStart and dateEnd, how would i compare the
two?
You do like this in the SQL query:

.... where DateFieldInData Base >= @Start and DateFieldInDate Base < @End

@Start and @End are parameters. You add Parameter objects to the Command
object with the values from dateStart and dateEnd.

If dateEnd is the date of the last day, you use dateEnd.AddDays (1) to
get the end time.
I'm guessing that the variable that I'm setting the date value out of
the datebase to, needs to be a datetime?
Yes.

--
Göran Andersson
_____
http://www.guffa.com
Aug 8 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

99
9105
by: Glen Herrmannsfeldt | last post by:
I was compiling a program written by someone else about six years ago, and widely distributed at the time. It also includes makefiles for many different systems, so I know it has been compiled with many different compilers. I got compile errors when it used va_arg to fetch an argument of type short. That seemed a little strange to me, so I changed it to int and it compiled just fine. So now I wonder, just what is the rule for va_arg...
5
2668
by: _Andy_ | last post by:
I'm looking for the alogithm to take a piece of 8-bit audio data, and scale it to a 16-bit short. I got as far as: private static short ByteToShort(byte b) { int word = 0; word |= ( ( b & 0x01 ) << 1 ); word |= ( ( b & 0x02 ) << 2 ); word |= ( ( b & 0x04 ) << 3 ); word |= ( ( b & 0x08 ) << 4 );
15
14290
by: Fritz Switzer | last post by:
I'd like to have a string assigned the value of a DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM" format. For example: DateTime.Now.AddMinutes(30) returns "00:30" DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"
4
11407
by: darrel | last post by:
I'm binding fileinformation to a repeater and attempting to display the 'lastWriteTime' property as a formatted date. This: <%# DataBinder.Eval(Container.DataItem, "LastWriteTime" %> Gives me the full date/time. This:
6
38949
by: Brandon | last post by:
I'm using PHP with MySQL 4.x and was having trouble converting a datetime from MySQL into a formatted string until I ran across this solution that converts a YYYY-MM-DD HH:MM:SS string into a Unix-style timestamp and then formats it. $timestamp = "2005-04-06 15:43:34"; $time = strtotime($timestamp); print date('Y-m-d \a\t H:i', $time)."\n"; However, it seems kind of counter productive. After all, aren't people
5
12465
by: rbtmaxwell | last post by:
Hello, Not sure If I'm posting in the correct group here, so I appologize in advance if I selected the wrong one. I am trying to initialize a short with a hex value... sounds trivial right? Well I have not found a way to do this in c# without the compiler complaining or throwing a exception when its executing the code.
7
13362
by: TheLostLeaf | last post by:
DateTime tTime = DateTime.Now; ------------------------------------------------------------------------------------------- tTime returns "1:59:00 PM" it never returns seconds. Database field is SQL datetime or smalldatetime.
3
30842
by: Tim | last post by:
Folks, I'm trying to format a print string so that it reports progress whilst processing a looping structure with a date time stamp appended to the end of the string. This started out life as a simple need to create a display that show progress to users when updating large tables in a data warehouse in real time. I have subsequently address that need through a different method, however I am challenged by the seeming impossibility to...
1
15361
by: Magnus.Moraberg | last post by:
Hi, I have the following event which checks if a cell in a dgv contains a date and if so, checks if it is formatted correctly. I don't think its good practice for be to try this by catching an exception. Is there a better way? Notice also my use of a dummy dateTime object. Also, does the DateTime object contain any information about how it should be formatted? For example - "Format Error: DateTime cell incorrectly formatted. Expected...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10350
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10351
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
10096
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
9174
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
7638
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
6866
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4311
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
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.