0

I want to do a sql statement which queries by timestamp using javascript.

Here is how i set my timestamp:

var startTime = new Date(year, month, day, 0, 0);
var endTime = new Date(year, month, day, 23, 59);

My sql statement is:

'SELECT * FROM proximate.user WHERE join_timestamp >= $1 ' +
'AND join_timestamp<=$2 ORDER BY user_id ASC';

$1 is startTime and $2 is endTime. Given if the startTime is Sat Dec 01 2012 00:00:00 GMT+0800 (SGT) and endTime is Sat Dec 01 2012 23:59:00 GMT+0800 (SGT), the executed statement returns results which include timestamp that is a day before the startTime.

Anyone has any idea why?

Thanks in advance.

4

1 回答 1

1

我的猜测是您收到了正确的结果,但忘记将返回的结果集的时间戳列转换为 GMT+8:“Sat Dec 01 2012 00:00:00 GMT+0800”= Fri Nov 30 16:00:00 UTC”。另一个选项 - 以 UTC 传递日期。实际上这取决于您想要获得什么:如果您需要在 12 月 1 日 GMT+8 加入的所有用户,则需要转换结果集,如果您需要在 12 月 1 日 UTC 加入的用户,则通过 UTC日期:“2012 年 12 月 1 日星期六 00:00:00 UTC”

于 2012-12-09T16:04:24.090 回答