Jump to content

timestamp


rashmi_k28

Recommended Posts

Hi,

 

I have a query like this

select timestamp, name from table where timestamp <= ('".$time."') and timestamp >= date_sub('".$time."',interval 1 day) group by timestamp order by timestamp.

 

All the records between these are fetched due to seconds in the timestamp.

 

The timestamp is difference of 10 minutes and seconds can be 01 or 02 so on.

 

Due to this seconds difference the value fetched is less by 1 for the day.

How to exclude the seconds and query for the 1 day interval difference

 

Link to comment
Share on other sites

When I query the timestamp

| 2008-08-08 06:40:01 |

| 2008-08-08 06:50:01 |

| 2008-08-08 07:00:02 |

| 2008-08-08 07:10:01 |

| 2008-08-08 07:20:01 |

| 2008-08-08 07:30:02 |

| 2008-08-08 07:40:01 |

| 2008-08-08 07:50:01 |

| 2008-08-08 08:00:02 |

| 2008-08-08 08:10:02 |

| 2008-08-08 08:20:05 |

| 2008-08-08 08:30:01 |

| 2008-08-08 08:40:01 |

| 2008-08-08 08:50:05 |

| 2008-08-08 09:00:02 |

| 2008-08-08 09:10:01 |

| 2008-08-08 09:20:01 |

| 2008-08-08 09:30:01 |

| 2008-08-08 09:40:02 |

| 2008-08-08 09:50:01 |

| 2008-08-08 10:00:01 |

| 2008-08-08 10:10:01 |

+---------------------+

 

But previous date timestamp may differ with the seconds

2008-08-07 09:10:01 |

| 2008-08-07 09:20:01 |

| 2008-08-07 09:30:01 |

| 2008-08-07 09:40:01 |

| 2008-08-07 09:50:01 |

| 2008-08-07 10:00:01 |

| 2008-08-07 10:10:01 |

| 2008-08-07 10:20:01 |

| 2008-08-07 10:30:01 |

| 2008-08-07 10:40:01 |

| 2008-08-07 10:50:01 |

| 2008-08-07 11:00:02 |

| 2008-08-07 11:10:01 |

| 2008-08-07 11:20:01 |

| 2008-08-07 11:30:01 |

| 2008-08-07 11:40:01 |

| 2008-08-07 11:50:02 |

| 2008-08-07 12:00:01 |

| 2008-08-07 12:10:01 |

| 2008-08-07 12:20:01 |

 

 

But When I use this timestamp to query the data from table,

Due to the seconds mistach the first value is missed out.

So how can i avoid it using the query excluding the seconds

If i use timestamp as 2008-08-07 12:20 then last value is missed out. It is considered as 2008-08-07 12:20:00

 

select timestamp, fieldname from table where timestamp <= ('".$time."') and timestamp >= date_sub('".$time."',interval 1 day)  group by timestamp order by timestamp.

 

 

 

 

Link to comment
Share on other sites

But When I use this timestamp to query the data from table,

Due to the seconds mistach the first value is missed out.

So how can i avoid it using the query excluding the seconds

I told you how to do this... have you tried?

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

 

Actually if I use date(timestamp)=date(now()) is for matching the date and current date. In similar way how to match only the format YYYY-mm-dd hr:min

and not seconds.

 

If I use the query as below

SELECT timestamp from tablename where substring(timestamp,1,16) <= ('2008-08-18 11:20') and substring(timestamp,1,16) >= date_sub('2008-08-18 11:20',interval 1 day) group by timestamp order by timestamp;

 

The output doesnot fetch the previous day's data at timestamp 2008-08-18 11:20 even if it present.

Link to comment
Share on other sites

Actually if I use date(timestamp)=date(now()) is for matching the date and current date. In similar way how to match only the format YYYY-mm-dd hr:min

and not seconds.

Nor should it.  Just always round up, then MOD 60, then FROM_UNIXTIME().

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.