Current location: Hot Scripts Forums » Programming Languages » PHP » Help with SQL & datetime-fields


Help with SQL & datetime-fields

Reply
  #1 (permalink)  
Old 06-15-04, 12:58 PM
flekso flekso is offline
New Member
 
Join Date: Jun 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Help with SQL & datetime-fields

Hi,

I have a little problem that goes beyond my understanding of SQL.

I have web-based gui that presents daily tasks that must be done. Every task has starting and ending point (stored as datetime-fields in mysql db)

e.g.

-----------------------------------------

--[date: 15.06.2004 - page 1 ]---

task 1. start: xxxxx end: xxxx
task 2. start: xxxxx end: xxxx

--[date: 16.06.2004 - page 2 ]---

task 3. start: xxxxx end: xxxx
task 4. start: xxxxx end: xxxx

------------------------------------------

Ok, no big deal selecting tasks that start on the same day.
e.g. SELECT * FROM foobar WHERE TO_DAYS(start) = TO_DAYS('2004-06-28');

... but how can I include to my query tasks that have started earlier (eg. 2004-06-27) and continue to another day ?

Thanks for help.
Reply With Quote
  #2 (permalink)  
Old 06-16-04, 07:41 AM
marklar's Avatar
marklar marklar is offline
Newbie Coder
 
Join Date: May 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Oops, didn't read this properly 1st time through so I've deleted my original post.

You can search both start and end fields and then order by one of them. I'm guessing you want all tasks that have started but not finished.

This sorts by start

SELECT * FROM foobar WHERE TO_DAYS(start) < TO_DAYS('2004-06-28') AND TO_DAYS(end) > TO_DAYS('2004-06-28') ORDER BY TO_DAYS(start) ASC;

Last edited by marklar; 06-16-04 at 08:29 AM.
Reply With Quote
  #3 (permalink)  
Old 06-16-04, 07:46 AM
Worm's Avatar
Worm Worm is offline
Newbie Coder
 
Join Date: Jun 2004
Location: Germany, Frankfurt am Main
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by flekso
Hi,

I have a little problem that goes beyond my understanding of SQL.

I have web-based gui that presents daily tasks that must be done. Every task has starting and ending point (stored as datetime-fields in mysql db)

e.g.

-----------------------------------------

--[date: 15.06.2004 - page 1 ]---

task 1. start: xxxxx end: xxxx
task 2. start: xxxxx end: xxxx

--[date: 16.06.2004 - page 2 ]---

task 3. start: xxxxx end: xxxx
task 4. start: xxxxx end: xxxx

------------------------------------------

Ok, no big deal selecting tasks that start on the same day.
e.g. SELECT * FROM foobar WHERE TO_DAYS(start) = TO_DAYS('2004-06-28');

... but how can I include to my query tasks that have started earlier (eg. 2004-06-27) and continue to another day ?

Thanks for help.
I think you will have to decide... either you want to sort it by date of beginning or by date of ending. The list you have pasted above must categorize the tasks bei any date, either beginning or ending. And if you select each row of the database, you can put a WHERE on the beginning date = '2004-06-28' which should also return the ending date. If you now sort your list, you could have something like this:

-----------------------------------------

--[date: 15.06.2004 - page 1 ]---

task 1. start: 15.06.2004 end: 15.06.2004
task 2. start: 15.06.2004 end: 23.06.2004

--[date: 16.06.2004 - page 2 ]---

task 3. start: 16.06.2004 end: 16.06.2004
task 4. start: 16.06.2004 end: 27.06.2004

------------------------------------------

Where is your problem, if i got you wrong...?
Reply With Quote
  #4 (permalink)  
Old 06-16-04, 08:38 AM
marklar's Avatar
marklar marklar is offline
Newbie Coder
 
Join Date: May 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
I don't know what's wrong with me today, you don't want what I said do you, so you have 2 choices as pointed out by Worm, either all tasks starting today but not finished OR all tasks started before and finishing today.

Starting today:
SELECT * FROM foobar WHERE TO_DAYS(start) = TO_DAYS('2004-06-28') AND TO_DAYS(end) => TO_DAYS('2004-06-28') ORDER BY TO_DAYS(start) ASC;

Finishing today:
SELECT * FROM foobar WHERE TO_DAYS(start) <= TO_DAYS('2004-06-28') AND TO_DAYS(end) = TO_DAYS('2004-06-28') ORDER BY TO_DAYS(start) ASC;

Last edited by marklar; 06-16-04 at 08:40 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
formmail problem gscraper Perl 12 08-27-04 03:06 AM
LWP posting variable numbers of fields? afenn Perl 1 05-14-04 11:02 PM
Help with ASP & FORMS blessedrub ASP 0 01-23-04 10:22 AM
ASP Calendar..HELP...pls jimthepict ASP 1 07-31-03 05:01 PM
change my field in this example sal21 ASP 3 07-14-03 02:49 AM


All times are GMT -5. The time now is 05:02 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.