Retrieving data from Postgres Sql and displaying in a datepicker - node.js

I am a newbie in fullstack development. I am doing my first project using postgresql, nodejs and express(ejs template). In my task list project i have a duedate option, where i enter a duedate(date picker) for a task and it get saved in the postgres database. I have an edit option aswell with a datepicker. how can i retreive the date in the 'dd/mm/yyyy' format from the database and display it inthe date picker in the edit page?.is it possible. Please help.
Thanks

What gets stored in the DB for date will probably look different then what you see on the front-end, simply because date / time is usually stored as UTC etc ( this will depend on how you have the table configured)
Next, you can use javascript built in date function like toLocaleDateString('en-US') to get a mm/dd/yyyy format from the stored date in the DB
What this means is that on the front-end you would pull the date from the DB as normal, then for the date-picker you would just pass the date over like
let myDate = new date([date from db); // this create a new date object off the date from the DB
//Now we make is a readable date
// myDate = myDate.toLocaleDateString('en-US'); // will give mm/dd/yyyy

Related

NodeJS and Firebase/Firestore track time and update automatically

so the functionality I'm trying to create is the user gives me a date eg 06/28/2020 and on 07/28/2020 I'll:
send them a notification
change the date I was storing from 06/28/2020 to 7/28/2020
start tracking for 08/28/2020 to repeat 1 & 2.
And I want to do this automatically. I can do the notification but I'm stuck on how to keep track of the date automatically every day to compare between today's date and the end date which is the 28th of next month and make the changes. Does firebase or nodejs have some feature/package to do this behind the scene without any external events after the user has input the end date?
Right now I can get the dates from firestore and compare it with today's date but ONLY when I have an event like when I go to my profile page. I can also update the date for next month using dateJS. But if I don't go to my page it won't trigger the function. I want to make it automatic and store it somewhere where it doesn't require a user's interaction to trigger it but happens automatically.
Note: The date can be different based on user input so it's not a fixed date. And I'm using NodeJS and firebase for my project.
Any help will be appreciated. Thanks!
You could make a cloud function that runs every 24 hours using pubsub. You can then get the current date using something like
const currentDate = new Date();
You can then check if that day is today, by checking if the timestamp in firestore is between now and 24 hours in the future. I would advice using the moment dependency for that. You could do something like:
const currentDate = new Date();
const tomorrow = moment(currentDate).add(24, 'hours');
if(yourDate > currentDate && yourDate < tomorrow){
// send notification
// update to next month
const nextMonth = moment(currentDate).add(1, 'month');
db.collection(path).doc(docId).update({
yourDate: nextMonth,
});
}
Note that this is pseudo code, I haven't fully tested it but I have used a similar technique in the past. This should do the trick for you I think

Historian retrieve data

I have an Excel worksheet that I have the data pulled from a Historian database for emission tags in a Wonderware server. I need to know how i can write the SQL query that uploads data between two date ranges.starte date end date.
I have collected the data and display I want, I just dont know how I can implement between two date ranges the user types in on another form. I DONT KNOW HOW TO DO THIS.
I have tried nothing because im not sure how to implement a parameter query with excel.
SET QUOTED_IDENTIFIER OFF
SELECT * FROM OPENQUERY(INSQL, "SELECT DateTime, [AB01_PE01], [NU_DC01_DX01_DISPLAY],
[NU_DC01_DX02_DISPLAY], [NU_DC02_DX01_DISPLAY], [NU_DC02_DX02_DISPLAY],
[NU_DC03_DX01_DISPLAY], [NU_DC03_DX02_DISPLAY], [NU_DC05_DX01_DISPLAY]
FROM WideHistory
WHERE wwRetrievalMode = 'Cyclic'
AND wwCycleCount = 14
AND wwVersion = 'Latest'
AND DateTime >= '20190501 06:00:00.000'
AND DateTime <= GetDate()")
what I want is where Datetime >= is I need to set up where it ask the user the start date and end date? I do not know how to do this in excel I am new to the historian add in.
Based on your comment response, I understand your real question is: how to parameterize SQL query in Excel. This video shows step by step guide to do that: https://youtu.be/xPalEw4xw1w?t=129

Date from SQL datebase to JCalander

I used http://toedter.com/ jDateChooser to get the date from user. But now I want to reset the selected date to the calendar from SQL database. This is the code I wrote to put selected date to database.
pst.setString(5, ((JTextField)datead.getDateEditor().getUiComponent()).getText());
I figured it out myself.
java.util.Date dateadx = new SimpleDateFormat("yyyy-MM-dd").parse(dateadm);
Here dateadm is the String variable which you want to store as date in JDateChooser.
Then you can simply call
datead.setDate(dateadx)
to set the date.

How to get the Current Date & Time Automatically to a Date Time Field

I have created a date time field I made today's date as the default value, Then I added it to a page layout and created a page, But the current Date Time is not picking up from the system.
I dont want to give the user to select a Date Time instead it should populated automatically
Is there anyway to achieve this without writing code in code behind files?
This is very similar to this question I think
SO - How to get Date and current time from the Date/Time column in SharePoint Custom list
My answer there gives a few options such as using the built in Created field, using a calendar template, a JavaScript hack and a custom field type.
Guys, fake [Today] trick worked for us - but prob is we only got the date value not datetime.
Janis, is it possible to get date and time both from the fake [today] column trick? pls refer few articles on the same
Does [Today] work?
If you have language pack applied to SharePoint, then you must use localized "Today" string.

Modx assign default date to template variable

I have a template variable of input type date but I'd like to have a default value of the current date at the time the document was first saved.
I've noticed that using the date formatter widget gives an option to "If no value, use current date" however it seems to use the date at the time it is being viewed rather than the date at the time the document was created.
Any help appreciated.
I think the only way to get the date when the article was saved for the first time is to use [ * createdon * ]
If there is a way to add the created date to a TV, I am not sure. I think your best shot would be to see if you have an event that you could "hook" you Template Variable, and then use the createdon variable everytime the article is saved! I am not sure this works, but This could be a possible!

Resources