Unix Technical Forum

datetime manipulation

This is a discussion on datetime manipulation within the MySQL forums, part of the Database Server Software category; --> I have an id in mySQL server with format dateStart DATETIME (// YYYY- MM-DD HH:MM:SS) Now I want to ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-04-2008, 06:24 AM
Slickuser
 
Posts: n/a
Default datetime manipulation

I have an id in mySQL server with format dateStart DATETIME (// YYYY-
MM-DD HH:MM:SS)

Now I want to sort the table by today and 1 week starting from now.
$today = date("Y-m-d h:i:s");

I am not sure how to achieve that, any help? thank you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-04-2008, 06:24 AM
Gordon Burditt
 
Posts: n/a
Default Re: datetime manipulation

>I have an id in mySQL server with format dateStart DATETIME (// YYYY-
>MM-DD HH:MM:SS)
>
>Now I want to sort the table by today and 1 week starting from now.
>$today = date("Y-m-d h:i:s");


What does it mean to sort by two different things?

>I am not sure how to achieve that, any help? thank you.


If you want to fetch records between today and 1 week starting from
now, you could do (this uses the MySQL server time, not the time
on the PHP server):

SELECT * FROM table WHERE dateStart >= now() AND dateStart < dateadd(now(),7);

If you also want to order by dateStart, you can add:

ORDER BY dateStart

SQL queries sort the output, not the table. If you don't specify ORDER BY,
you have no complaint about the order of the rows in the result set.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-04-2008, 06:24 AM
Michael Austin
 
Posts: n/a
Default Re: datetime manipulation

Slickuser wrote:
> I have an id in mySQL server with format dateStart DATETIME (// YYYY-
> MM-DD HH:MM:SS)
>
> Now I want to sort the table by today and 1 week starting from now.
> $today = date("Y-m-d h:i:s");
>
> I am not sure how to achieve that, any help? thank you.


google mysql date and read the docs. they are replete with examples on
date time manipulation.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-06-2008, 02:04 PM
Captain Paralytic
 
Posts: n/a
Default Re: datetime manipulation

On 4 Mar, 02:43, gordonb.9z...@burditt.org (Gordon Burditt) wrote:
> SQL queries sort the output, not the table.

Not always totally true. Sometimes a table index will be used to
supply the data in the correct order for the output.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-06-2008, 02:04 PM
Gordon Burditt
 
Posts: n/a
Default Re: datetime manipulation

>> SQL queries sort the output, not the table.
>Not always totally true. Sometimes a table index will be used to
>supply the data in the correct order for the output.


That sorts the output, not the table.

If you said "sometimes a table index will be used to physically
order the data in the table" and could demonstrate portable SQL to
do that, OK. But there's no SQL to retrieve the table in physical
order.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:18 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com