Google Charts Horizontal Axis wrong date - date

In the pic above, the horizontal axis is a day ahead of the actual values. Very new to google charts and cant figure out what the issue could be. I have verified the data being passed to the chart is the 14th, 15th, and 16th.
google.visualization.ComboChart

Found an answer to this. The problem was javascript subtracting a day from the date range.
Here is how I was initially setting the date:
var dt = new Date($(child).text());
dt.setDate(dt.getDate());
addData.push(dt);
Solution
var year = parseInt($(child).text().split("-")[0]);
var month = parseInt($(child).text().split("-")[1])-1;
var day = parseInt($(child).text().split("-")[2]);
var dt = new Date(year, month, day);
addData.push(dt);

Related

Problem with understanding date formats in googleScripts

I made a few functions with GoogleSheets using AppsScripts for simple task a few times in previous years. I always had problems when taking dates from cells/ranges and processing them, but somehow alwaays found a workaround, so that I did not have to deal with it. Well, this time I can not find a workaround, so I will try to explain my problems with the following code:
function getDates(){
var s = SpreadsheetApp.getActiveSpreadsheet();
var sht = s.getSheetByName('Dates');
var date = sht.getRange(2,1).getValues();
Logger.log(date[0][0]); //output is Tue Jun 08 18:00:00 GMT-04:00 2021
var datumFilter= Utilities.formatDate(date[0][0], "GMT+1", "dd/mm/yy");
Logger.log(datumFilter); //output is 08/00/21
var outrng = sht.getRange(25,1);
outrng.setValue(date);
}
The first targeted cell ('var date') has a value of "9.6.21" in the spreadsheet. The cell is formatted as a date and it opens a calendar when double-clicked. When I set the new cells values (with 'outrng.setValue(date);'), the result is OK, with the same date as in the original cell.
But I do not need to simply transfer the values, I want to implement them in some loops and I have no idea how to simply get the date in the same format or at least the same date in the script as it is in the cell. As you can see from the logger, the values there are different. A simple d/m/yy format would be sufficient.
My spreadsheet settings are set to my local time (Slovenia, GMT+1).
I am guessing that I am missing some basics here. I have spent many hours trying to understand it, so any help is highly appreciated!
Cooper already answered all your questions in the comment. I'd like to add on and show you an example on what it would like and add some modifications.
Code:
function getDates() {
var s = SpreadsheetApp.getActiveSpreadsheet();
var sht = s.getSheetByName('Dates');
// get last row of the sheet
var lastRow = sht.getLastRow();
// get your sheet's timezone
var timezone = SpreadsheetApp.getActive().getSpreadsheetTimeZone();
var output = [];
// getValues is mostly used for multiple cells returning a 2D array
// use getValue for single cells to return its actual value
// but since function name is getDates, I assume column A is all dates
// so we fetch the whole column (A2:A[lastRow]) except the header
var dates = sht.getRange("A2:A" + lastRow).getValues();
// for each date on that column, we format the date to d/M/yy
// m/mm = minute
// M/MM = month
dates.forEach(function ([date]){
Logger.log(date);
var datumFilter= Utilities.formatDate(new Date(date), timezone, "d/M/yy");
Logger.log(datumFilter);
// collect all dates in an array
output.push([datumFilter]);
});
// assign all the dates in the array onto range B2:B
sht.getRange(2, 2, output.length, 1).setValues(output);
}
Sample data:
Logs:
Output:
Note:
The output on sheets is not equal to logs due to the formatting of my sheet.

Calculating days between two dates with Flutter

I want to develop a small Flutter app that calculates the number of days between two dates, using the following steps :
Ask the user to type the first date (Turkish notation; with whitespaces: "dd mm yyyy")
Ask the user to type the second date.
After that the program should calculates the number of days between the two dates and display it.
Given dateText and dateText2, this will give you the days between:
var dateArray = dateText.split(' '); // [d, m, y]
var date = new DateTime(int.parse(dateArray[2]), int.parse(dateArray[1]), int.parse(dateArray[0]));
var dateArray2 = dateText2.split(' ');
var date2 = new DateTime(int.parse(dateArray2[2]), int.parse(dateArray2[1]), int.parse(dateArray2[0]));
var daysBetween = date2.difference(date).inDays;
print(daysBetween); // 365

How to format axis real time amcharts hh:mm?

I use amchart, I want to create a real time chart, and set minDate, maxDate for x axis, and format it to hh:mm. I tried use minimumDate, maximumDate, "minPeriod" : "hh", but it fail.
My code:
demo1.
I want to use amchart to build a real time chart like: demo2 (use flot chart).
The labels xaxis is static not run, and to accumulate data.
Help me, please!
Thank you!
When updating the time, you need to set a new date instance or a separate value. Updating the startDate variable updates all the data points that share that date object as AmCharts doesn't clone the date objects in your dataProvider. A quick fix is to use the millisecond timestamp result from the setMinutes call, for example:
var newDate = startDate.setMinutes(startDate.getMinutes() + 10);
var visits = randomIntFromInterval(50, 100);
chartData.push({
date: newDate,
visits: visits
});
AmCharts will internally convert the millisecond values to a new Date object. This should be applied to your generate and update methods.
minPeriod should be set to the minimum period between your datapoints. As you're adding data in 10 minute increments, this should be "mm", not "hh".
By default, the categoryAxis does not support setting a minimumDate and maximumDate, however, you can use AmCharts' datePadding plugin to add this functionality. This plugin will allow you to set a minimumDate and maximumDate property in your categoryAxis when you add the following script tag after your AmCharts includes:
<script src="//www.amcharts.com/lib/3/plugins/tools/datePadding/datePadding.min.js"></script>
In order to maintain your date range after updating the chart, you have to call the plugin's AmCharts.datePaddingProcess method to re-update the range before redrawing the chart.
Here's what your updateChart method will look like after using the datePadding plugin:
function updateChart() {
var newDate = startDate.setMinutes(startDate.getMinutes() + 10);
var visits = randomIntFromInterval(50, 100);
chart.dataProvider.push({
date:newDate,
visits:visits
});
AmCharts.datePaddingProcess(chart, true);
chart.validateData();
}
And here's what your categoryAxis will look like:
"categoryAxis": {
"parseDates": true,
"gridAlpha": 0.15,
"axisColor": "#DADADA",
"minPeriod" : "mm",
"minimumDate": min,
"maximumDate": max
},
Updated fiddle

UWP calendar view visible date range

I would like to know how to get the range of dates the user is able to see on the Universal Windows Platform CalendarView control. I already tried looking on the Microsoft website but i can't seem to find anything.
1. By default, the minimum date shown in the CalendarView is 100 years prior to the current date, and the maximum date shown is 100 years past the current date.
You can change the minimum and maximum dates that the calendar shows by setting the MinDate and MaxDate properties. For example like this:
calendarView.MinDate = new DateTime(2000, 1, 1);
calendarView.MaxDate = new DateTime(2099, 12, 31);
You can also get the range of dates like this:
var minDate = calendarView.MinDate;
var maxDate = calendarView.MaxDate;
2. If what you want to do is changing the visible region of the CalendarView (by default it starts with the month view open, it shows 6 rows of dates which contain the current month.), you can use CalendarView.SetDisplayDate method for example like this:
DateTime localTime = new DateTime(2007, 07, 12, 06, 32, 00);
DateTimeOffset dateAndOffset = new DateTimeOffset(localTime, TimeZoneInfo.Local.GetUtcOffset(localTime));
calendarView.SetDisplayDate(dateAndOffset);
In this sample, the CalendarView will show the month 2007/7.
3. As I said, by default the number of weeks shown in the calendar view is 6, you can change it by CalendarView.NumberOfWeeksInView property, for example in xaml code:
<CalendarView x:Name="calendarView" NumberOfWeeksInView="8" />
Or code behind:
calendarView.NumberOfWeeksInView = 8;
The minimum number of weeks to show is 2, the maximum is 8;
4. Besides the month view, there are also year view and decade view in CalendarView, you can change it with CalendarView.DisplayMode property for example in xaml code:
<CalendarView x:Name="calendarView" DisplayMode="Year"/>
Or in code behind:
calendarView.DisplayMode = CalendarViewDisplayMode.Decade;
Since you asked a quite simple but broad question, I list every possibilities I could think about. If you have any other questions about this control, please check CalendarView class again.

pickdate.js parameters and monthPicker

I'm trying to suit well this plugin pickadate.js v3.3.1 but I'm facing some difficulties.
First, I need to restrict selection of only future dates, 3 months from today's date. The docs didn't help me much so tried to do it this way. But it's not working.
Second, can I change this to a MONTH PICKER only? I need this for a Credit Card Expiry date field input.
The documentation isn't very great, But I guess being a new plugin I can use some good help of geeks here.
<script>
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+3;
$('#pickdate').pickadate({
// Escape any “rule” characters with an exclamation mark (!).
format: 'mmm dd , yyyy',
formatSubmit: 'yyyy/mm/dd',
hiddenPrefix: 'prefix__',
hiddenSuffix: '__suffix',
min: new Date(),
max: mm
//min: new Date(),
//max: (new Date() + 10)
})
$('#picktime').pickatime();
</script>
From the docs:
If dateMax or dateMin is an integer, it represents the relative number
of days till the min or max date.
I couldn't find any mentioning in the docs of a month picker. Why not use a standard dropdown ()?
What could prove to be of use to you with regards to range, again from the docs, is:
dateMin and dateMax can be either
an array representing a date ([ yyyy, mm, dd ])