Javascript Time Frame
I'm trying to write a Node app that grabs data entries from MySQL based on a time frame equal to the beginning and end of the current work week.
Here's the Node-MySQL query:
function retrieveSales(){
connection.query('select * from sales_entries where date BETWEEN ? AND ?',
timeFrame,
function (err, rows, fields) {
var sales = new Array();
for (x=0;x<rows.length;x++){
sales.push(rows[x]);
}
return sales;
});
}
where timeFrame
is an array of two dates in datetime
format, which is the second-specific time data-type that MySQL offers as a default. ( 31/12/2010 03:55 AM )
The problem is, I've never worked much with dates in JS. So I have two questions:
Would it be better to record a different date format to the database, or is datetime fine?
How should I generate this array with values equal to the beginning of the first day of the current work week (monday) and end of the last day of the current work week (friday) respectively?
The Fiddle
Here's the JSFiddle, including three functions; retrieveSales
, which performs the query, dateTime()
, returning the current time in datetime format, and retrieveData
which is the main function that will call all necessary queries.