NodeJs and MySQL timestamp
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I need to create a report that will produce a list of instructors and the students that visited the lab under those instructors broken down by date.
But currently I'm adding the checkIn and checkOut time using a getTime function and saving that time as VARCHAR in MySQL because I had problems with the timestamp in MySQL and every check in/check out is it's own row. I'm also afraid that I won't be able to use that data to produce the report correctly.
How can I make it to where when someone checks in a row is created and when they check out later their previous row is updated with the current datetime as checkOut?
// Checking In/Out users
router.post("/checkin", (req, res) => {
const id = req.body.create_id
const firstName = req.body.create_first_name
const lastName = req.body.create_last_name
const checkIn = getDateTime();
const checkOut = getDateTime();
console.log("Checking In...")
console.log("ID: " + req.body.create_id)
console.log("First Name: " + req.body.create_first_name)
console.log("Last Name: " + req.body.create_last_name)
console.log(checkIn)
console.log(checkOut)
// Checking Student In
if(req.body.person === "Student" && req.body.checkInOut === "checkIn") {
queryString = "INSERT INTO students ( student_id ,firstName, lastName, checkIn) VALUES(?, ?, ?, ?)"
getConnection().query(queryString, [id, firstName, lastName, checkIn], (err, rows, fields) => {
// If error occures
if(err) {
console.log("Failed to check in new user: " + err)
res.sendStatus(500)
return
}
console.log("Checked in new user with id: ", id)
})
}
// Checking Student Out
else if(req.body.person === "Student" && req.body.checkInOut === "checkOut") {
queryString = "INSERT INTO students ( student_id ,firstName, lastName, checkOut) VALUES(?, ?, ?, ?)"
getConnection().query(queryString, [id, firstName, lastName, checkOut], (err, rows, fields) => {
// If error occures
if(err) {
console.log("Failed to check out new user: " + err)
res.sendStatus(500)
return
}
console.log("Checked out user with id: ", id)
})
}
javascript mysql node.js ejs
add a comment |
I need to create a report that will produce a list of instructors and the students that visited the lab under those instructors broken down by date.
But currently I'm adding the checkIn and checkOut time using a getTime function and saving that time as VARCHAR in MySQL because I had problems with the timestamp in MySQL and every check in/check out is it's own row. I'm also afraid that I won't be able to use that data to produce the report correctly.
How can I make it to where when someone checks in a row is created and when they check out later their previous row is updated with the current datetime as checkOut?
// Checking In/Out users
router.post("/checkin", (req, res) => {
const id = req.body.create_id
const firstName = req.body.create_first_name
const lastName = req.body.create_last_name
const checkIn = getDateTime();
const checkOut = getDateTime();
console.log("Checking In...")
console.log("ID: " + req.body.create_id)
console.log("First Name: " + req.body.create_first_name)
console.log("Last Name: " + req.body.create_last_name)
console.log(checkIn)
console.log(checkOut)
// Checking Student In
if(req.body.person === "Student" && req.body.checkInOut === "checkIn") {
queryString = "INSERT INTO students ( student_id ,firstName, lastName, checkIn) VALUES(?, ?, ?, ?)"
getConnection().query(queryString, [id, firstName, lastName, checkIn], (err, rows, fields) => {
// If error occures
if(err) {
console.log("Failed to check in new user: " + err)
res.sendStatus(500)
return
}
console.log("Checked in new user with id: ", id)
})
}
// Checking Student Out
else if(req.body.person === "Student" && req.body.checkInOut === "checkOut") {
queryString = "INSERT INTO students ( student_id ,firstName, lastName, checkOut) VALUES(?, ?, ?, ?)"
getConnection().query(queryString, [id, firstName, lastName, checkOut], (err, rows, fields) => {
// If error occures
if(err) {
console.log("Failed to check out new user: " + err)
res.sendStatus(500)
return
}
console.log("Checked out user with id: ", id)
})
}
javascript mysql node.js ejs
add a comment |
I need to create a report that will produce a list of instructors and the students that visited the lab under those instructors broken down by date.
But currently I'm adding the checkIn and checkOut time using a getTime function and saving that time as VARCHAR in MySQL because I had problems with the timestamp in MySQL and every check in/check out is it's own row. I'm also afraid that I won't be able to use that data to produce the report correctly.
How can I make it to where when someone checks in a row is created and when they check out later their previous row is updated with the current datetime as checkOut?
// Checking In/Out users
router.post("/checkin", (req, res) => {
const id = req.body.create_id
const firstName = req.body.create_first_name
const lastName = req.body.create_last_name
const checkIn = getDateTime();
const checkOut = getDateTime();
console.log("Checking In...")
console.log("ID: " + req.body.create_id)
console.log("First Name: " + req.body.create_first_name)
console.log("Last Name: " + req.body.create_last_name)
console.log(checkIn)
console.log(checkOut)
// Checking Student In
if(req.body.person === "Student" && req.body.checkInOut === "checkIn") {
queryString = "INSERT INTO students ( student_id ,firstName, lastName, checkIn) VALUES(?, ?, ?, ?)"
getConnection().query(queryString, [id, firstName, lastName, checkIn], (err, rows, fields) => {
// If error occures
if(err) {
console.log("Failed to check in new user: " + err)
res.sendStatus(500)
return
}
console.log("Checked in new user with id: ", id)
})
}
// Checking Student Out
else if(req.body.person === "Student" && req.body.checkInOut === "checkOut") {
queryString = "INSERT INTO students ( student_id ,firstName, lastName, checkOut) VALUES(?, ?, ?, ?)"
getConnection().query(queryString, [id, firstName, lastName, checkOut], (err, rows, fields) => {
// If error occures
if(err) {
console.log("Failed to check out new user: " + err)
res.sendStatus(500)
return
}
console.log("Checked out user with id: ", id)
})
}
javascript mysql node.js ejs
I need to create a report that will produce a list of instructors and the students that visited the lab under those instructors broken down by date.
But currently I'm adding the checkIn and checkOut time using a getTime function and saving that time as VARCHAR in MySQL because I had problems with the timestamp in MySQL and every check in/check out is it's own row. I'm also afraid that I won't be able to use that data to produce the report correctly.
How can I make it to where when someone checks in a row is created and when they check out later their previous row is updated with the current datetime as checkOut?
// Checking In/Out users
router.post("/checkin", (req, res) => {
const id = req.body.create_id
const firstName = req.body.create_first_name
const lastName = req.body.create_last_name
const checkIn = getDateTime();
const checkOut = getDateTime();
console.log("Checking In...")
console.log("ID: " + req.body.create_id)
console.log("First Name: " + req.body.create_first_name)
console.log("Last Name: " + req.body.create_last_name)
console.log(checkIn)
console.log(checkOut)
// Checking Student In
if(req.body.person === "Student" && req.body.checkInOut === "checkIn") {
queryString = "INSERT INTO students ( student_id ,firstName, lastName, checkIn) VALUES(?, ?, ?, ?)"
getConnection().query(queryString, [id, firstName, lastName, checkIn], (err, rows, fields) => {
// If error occures
if(err) {
console.log("Failed to check in new user: " + err)
res.sendStatus(500)
return
}
console.log("Checked in new user with id: ", id)
})
}
// Checking Student Out
else if(req.body.person === "Student" && req.body.checkInOut === "checkOut") {
queryString = "INSERT INTO students ( student_id ,firstName, lastName, checkOut) VALUES(?, ?, ?, ?)"
getConnection().query(queryString, [id, firstName, lastName, checkOut], (err, rows, fields) => {
// If error occures
if(err) {
console.log("Failed to check out new user: " + err)
res.sendStatus(500)
return
}
console.log("Checked out user with id: ", id)
})
}
javascript mysql node.js ejs
javascript mysql node.js ejs
edited Nov 18 '18 at 3:20
Steven
asked Nov 16 '18 at 22:54
StevenSteven
246
246
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
you can also create table like
CREATE TABLE `students` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`first_name` varchar(128) NOT NULL DEFAULT '',
`is_checkout` boolean NOT NULL DEFAULT FALSE,
`last_name` varchar(128) NOT NULL DEFAULT '',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) CHARSET=utf8mb4 COLLATE utf8mb4_general_ci;
When user check in you only create one row, current_timestamp of mysql will record current date time
and when user check out you find students by id where student.is_checkout = false and update column is_checkout to true and at that time updated_at will be record current timestamp of checkout date
Thank you very much, I'll edit this once I get it implemented.
– Steven
Nov 18 '18 at 18:12
I got it working. How would I be able to display my MySQL data in html?
– Steven
Nov 19 '18 at 18:35
you can use moment js to parse it to string or parse it to string from server and return data to client
– Duong Pham
Nov 20 '18 at 3:46
I got MySQL data displayed for now, if I need to make some changes I will consider it. Thank you
– Steven
Nov 21 '18 at 5:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346448%2fnodejs-and-mysql-timestamp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
you can also create table like
CREATE TABLE `students` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`first_name` varchar(128) NOT NULL DEFAULT '',
`is_checkout` boolean NOT NULL DEFAULT FALSE,
`last_name` varchar(128) NOT NULL DEFAULT '',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) CHARSET=utf8mb4 COLLATE utf8mb4_general_ci;
When user check in you only create one row, current_timestamp of mysql will record current date time
and when user check out you find students by id where student.is_checkout = false and update column is_checkout to true and at that time updated_at will be record current timestamp of checkout date
Thank you very much, I'll edit this once I get it implemented.
– Steven
Nov 18 '18 at 18:12
I got it working. How would I be able to display my MySQL data in html?
– Steven
Nov 19 '18 at 18:35
you can use moment js to parse it to string or parse it to string from server and return data to client
– Duong Pham
Nov 20 '18 at 3:46
I got MySQL data displayed for now, if I need to make some changes I will consider it. Thank you
– Steven
Nov 21 '18 at 5:51
add a comment |
you can also create table like
CREATE TABLE `students` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`first_name` varchar(128) NOT NULL DEFAULT '',
`is_checkout` boolean NOT NULL DEFAULT FALSE,
`last_name` varchar(128) NOT NULL DEFAULT '',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) CHARSET=utf8mb4 COLLATE utf8mb4_general_ci;
When user check in you only create one row, current_timestamp of mysql will record current date time
and when user check out you find students by id where student.is_checkout = false and update column is_checkout to true and at that time updated_at will be record current timestamp of checkout date
Thank you very much, I'll edit this once I get it implemented.
– Steven
Nov 18 '18 at 18:12
I got it working. How would I be able to display my MySQL data in html?
– Steven
Nov 19 '18 at 18:35
you can use moment js to parse it to string or parse it to string from server and return data to client
– Duong Pham
Nov 20 '18 at 3:46
I got MySQL data displayed for now, if I need to make some changes I will consider it. Thank you
– Steven
Nov 21 '18 at 5:51
add a comment |
you can also create table like
CREATE TABLE `students` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`first_name` varchar(128) NOT NULL DEFAULT '',
`is_checkout` boolean NOT NULL DEFAULT FALSE,
`last_name` varchar(128) NOT NULL DEFAULT '',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) CHARSET=utf8mb4 COLLATE utf8mb4_general_ci;
When user check in you only create one row, current_timestamp of mysql will record current date time
and when user check out you find students by id where student.is_checkout = false and update column is_checkout to true and at that time updated_at will be record current timestamp of checkout date
you can also create table like
CREATE TABLE `students` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`first_name` varchar(128) NOT NULL DEFAULT '',
`is_checkout` boolean NOT NULL DEFAULT FALSE,
`last_name` varchar(128) NOT NULL DEFAULT '',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) CHARSET=utf8mb4 COLLATE utf8mb4_general_ci;
When user check in you only create one row, current_timestamp of mysql will record current date time
and when user check out you find students by id where student.is_checkout = false and update column is_checkout to true and at that time updated_at will be record current timestamp of checkout date
answered Nov 18 '18 at 3:32
Duong PhamDuong Pham
161
161
Thank you very much, I'll edit this once I get it implemented.
– Steven
Nov 18 '18 at 18:12
I got it working. How would I be able to display my MySQL data in html?
– Steven
Nov 19 '18 at 18:35
you can use moment js to parse it to string or parse it to string from server and return data to client
– Duong Pham
Nov 20 '18 at 3:46
I got MySQL data displayed for now, if I need to make some changes I will consider it. Thank you
– Steven
Nov 21 '18 at 5:51
add a comment |
Thank you very much, I'll edit this once I get it implemented.
– Steven
Nov 18 '18 at 18:12
I got it working. How would I be able to display my MySQL data in html?
– Steven
Nov 19 '18 at 18:35
you can use moment js to parse it to string or parse it to string from server and return data to client
– Duong Pham
Nov 20 '18 at 3:46
I got MySQL data displayed for now, if I need to make some changes I will consider it. Thank you
– Steven
Nov 21 '18 at 5:51
Thank you very much, I'll edit this once I get it implemented.
– Steven
Nov 18 '18 at 18:12
Thank you very much, I'll edit this once I get it implemented.
– Steven
Nov 18 '18 at 18:12
I got it working. How would I be able to display my MySQL data in html?
– Steven
Nov 19 '18 at 18:35
I got it working. How would I be able to display my MySQL data in html?
– Steven
Nov 19 '18 at 18:35
you can use moment js to parse it to string or parse it to string from server and return data to client
– Duong Pham
Nov 20 '18 at 3:46
you can use moment js to parse it to string or parse it to string from server and return data to client
– Duong Pham
Nov 20 '18 at 3:46
I got MySQL data displayed for now, if I need to make some changes I will consider it. Thank you
– Steven
Nov 21 '18 at 5:51
I got MySQL data displayed for now, if I need to make some changes I will consider it. Thank you
– Steven
Nov 21 '18 at 5:51
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346448%2fnodejs-and-mysql-timestamp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown