I am using the Google Visualization API to generate an annotation chart.
I fetch articles and their dates from my database. The dates are in the string format 'YYYYMMDD'.
While creating the data table for the chart, I am using the following code to add the date.
dataTable.addColumn('date', 'ArticleDate');
dataTable.addColumn('string', 'ArticleInfo');
for(i=0;i<searchResultsJSON.length;i++){
var yearValue = parseInt(searchResultsJSON[i].date.substr(0,4));
var monthValue = parseInt(searchResultsJSON[i].date.substr(4,6)) - 1;
var dayValue = parseInt(searchResultsJSON[i].date.substr(6,8));
dataTable.addRow([Date(yearValue,monthValue,dayValue),'<a class=\"tooltipLink\" onclick=\"getDoc(\''+searchResultsJSON[i].path+'\');return false;\">'+searchResultsJSON[i].title+'</a><br/\><br/\>']);
}
Now, I would like to know the number of articles on each day, so I run an aggregation query on the datatable.
var result = google.visualization.data.group(dataTable,[0],[{'column': 0, 'aggregation': google.visualization.data.count, 'type': 'date'}]);
However, I am stuck at this point with an error with the date format.
Error: Type mismatch. Value Mon Jun 16 2014 13:08:20 GMT+0200 (W. Europe Daylight Time) does not match type date in column index 0
at Error (native)
This has taken most of the morning and is really holding up progress. Any help at all would be great.
Thanks!
You are missing the new keyword in front of your Date constructor:
dataTable.addRow([new Date(yearValue,monthValue,dayValue),'<a class=\"tooltipLink\" onclick=\"getDoc(\''+searchResultsJSON[i].path+'\');return false;\">'+searchResultsJSON[i].title+'</a><br/\><br/\>']);
Related
I am writing a method in lambda using node.js and I have SQL Query in that method and I want current time so I will get that
here is my query I am using in that function
let sql =`UPDATE ctrData2.Tag SET Name=?, Description=?, UpdatedBy=?, UpdatedDate= now() WHERE TagId=?`;
SO what is the right way to get the current time?
JavaScript has Date object for working with dates:
let now = new Date();
This gives you the current Date, e.g.
Tue Jul 07 2020 10:42:56 GMT+0300 (East Africa Time)
Take a look at the documentation for the various ways you can manipulate Date objects.
I've some problems with extracting DateTime field from a database using oracledb-node driver.
I've in the database two records with DateTime field like this.
# |MY_DATE |SESSIONTIMEZONE
1 |2020-05-02 00:00:00|Europe/Berlin
2 |2020-03-02 00:00:00|Europe/Berlin
When I retrieve it with oracledb-node to convert it into JSON, the second record changes day.
First Record
Rest API (JSON)
"2020-05-01T22:00:00.000Z"
Javascript Date
Sat May 02 2020 00:00:00 GMT+0200 (Ora legale dell'Europa centrale)
Second Record
Rest API (JSON)
"2020-03-01T22:00:00.000Z"
Javascript Date
Sun Mar 01 2020 23:00:00 GMT+0100 (Ora standard dell'Europa centrale)
I suppose that I'm getting in trouble with Daylight Saving Time.
Can someone help me with the right approach?
Thank you.
Does this help?
const dates = ["|2020-05-02 00:00:00|Europe/Berlin", "|2020-03-02 00:00:00|Europe/Berlin"];
const DateTime = luxon.DateTime;
dates.forEach(str => {
const [, dStr, tz] = str.split("|")
const d = DateTime.fromISO(dStr.replace(" ", "T"), {
zone: tz
});
console.log(d.toISO());
console.log(d.toUTC().toISO());
})
<script src="https://cdn.jsdelivr.net/npm/luxon#1.24.1/build/global/luxon.min.js"></script>
According to #Cristopher comment to my question, the problem was that my node.js backend code was working with a different Timezone compared to the one set in the oracle database.
Following the node-oracledb documentation about How to fetch Datetime fields, I've set the environment variable ORA_SDTZ='Europe/Berlin' according to the timezone of the database.
Some quick tips to help the troubleshooting:
How to get the database Timezone
SELECT sessiontimezone FROM DUAL;
How to get the node.js environment TimeZone
console.log(Intl.DateTimeFormat().resolvedOptions().timeZone)
I have a Google Forms with a date information like this:
enter image description here
This information I store into Google Spreadsheet along Google Apps Script; however in this spreadsheet, it doesn't store right date, it stores other date.
enter image description here
I use this Javascript code:
var response = '2017-12-07 08:00'; //Value from Google Form
var fecha_inicial = Utilities.formatString(response);
fecha_inicial_Date = new Date(fecha_inicial.substr(0, 10) + "T" +
fecha_inicial.substr(11, fecha_inicial.length)); //Thu Dec 07 2017 08:00:00 GMT-0500 (EST)
This form is executed in a gmail account in Spain.
GMT-0500 is not Spain's time zone. Spain is plus one. So there is a 6 hour difference between GMT-0500 and your time zone. To get your time zone:
var myTimeZone = Session.getScriptTimeZone();//Get the scripts time zone
I'm guessing the question here is, how do I make the form date and the sheet date the same?
In the google sheet have you tried changing the format of the date column? Select the whole column and in the menu click Format -> Number and then choose the format you want.
If you want to manipulate the timestamp in the App script I recommend using the moment library - Mlj57Yi463PVmHumHxq4bkaUlUqvRc4KT then add this code to use it:
var moment = Moment.moment
I am a newbie in javascript, come to my question.
I am using ionic 2 build application in which i am using date time picker for taking a time.
I am getting a a time format is in the "hh:mm" using time picker. eg(10:11) which is in string format and i am using Date() function which give me date is in something like
"Mon Aug 01 2016 01:32:03 GMT-0700 (Pacific Daylight Time)"
I want to replace "hh:mm"(01:32) from Date object with my string output of "hh:mm"(10:11) and then want to convert that into new Date object.
I also tried split and slice function but doesn't work.
If i get some guide about this will be very helpful.
I will be very helpful to all of you.
thanks
First of all, read up on Date.
In your case, the following code is a starting point.
var d = new Date();
d.setHours('10');
d.setMinutes('11');
Of course, you should exchange '10' and '11' with your picker data. Also, there are many other methods you can use on the Date object.
I am using Facebook FQL to get photos and the time when they were created. The problem is am getting the created time as some long integer value e.g. 1306776492.
Now I am unable to convert it to proper date time using javascript.
Can anyone point me in the right direction
You can set a Date objects time with the setTime method.
var d = new Date();
d.setTime(1306776492*1000);
document.write(d);
returns
Mon May 30 2011 20:28:12 GMT+0300 (FLE
Daylight Time)
http://jsfiddle.net/niklasvh/ANRcm/
If you want the date to be printed in a different format, just have a look at the other methods available for Date()