I have created 3 outlets for labels,1 action for button and 1 outlet for UIDatePickerView. lblField displays the current date with month, date and year[January 25, 2017] format. lblField2 displays the selected dates by the user after pressing dueDate action. Now, I need to calculate the differences between the current date and selected date i.e (lblField2 - lblField) in lblField3. How can i show the difference value in months and days in Swift3. I need strictly for Swift3 ?
You can use dateComponentsFormatter for that.
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.month,.day]
formatter.maximumUnitCount = 2
formatter.unitsStyle = .full
lblField3.text = formatter.string(from: Date(), to: datePicker.date) ?? ""
If you want difference with month and day specific that you can use Calendar this way.
let components = Calendar.current.dateComponents([.month, .day], from: Date(), to: datePicker.date)
let dayDifference = components.day!
let monthDifference = components.month!
var date = NSDate().dateStringWithFormat(format: "dd.MM.YYY")
print(date)
15.02.2017
this will be the date formater easy and new single line sytax
Related
I am trying to compare current date with report date. The report date comes in this format: "2022-05-30 00:00:00.000000", whereas the current date I want to be in YYYY-MM-DD.
How can I either change the format, or strip the clock time from the timestamp?
var moment = require('moment');
var currentDate = moment().format("YYYY-MM-DD")
const jsonData = pm.response.json();
let date = (jsonData['data'][0]['date'])
pm.test("Fresh data is available", function () {
pm.expect(date).to.eql(currentDate);
});
As the datatype of the Date is string so you can use .substring() to extract only the portion you want. And in case of date, you want first 10 characters, i.e.,'2022-05-30' instead of '2022-05-30 00:00:00.000000'.
So you can use : jsonData.data[0].date.substring(0,10)
I am using Jquery-ui-datepicker as inline with multidate: true. when i select multiple dates and click outside the calendar still the last selected date is highlighted. I want to remove the highlight when we click outside the calendar after the dates got selected
I have tried to remove the active class from the date, but what is ts doing is from UI the highlight is going Off, but the datepicker is not updated, so when i click on other date both the dates are getting highlighted.
Another issue is like if i call update method, it is working fine but the thing is the calendar is resetted to current month.
I want to stay in the month where the user selected the dates, for example, i am selecting dates in November, if i update the datepicker, it is showing the "September" month which is current month.
$('.date').datepicker()
var new_options = {
multidate: true,
startDate: new Date,
todayHighlight: true,
// daysOfWeekHighlighted: [0, 6],
endDate: new Date('12/31/2050'),
dateFormat: 'mm-dd-yyyy',
beforeShowDay: function(date){
let formattedDate = moment(date).format("MM/DD/YYYY");
if ($.inArray(formattedDate, already_active_generalHolidays) != -1){
return {
classes: 'generalHolidayClass'
};
}
}
Power BI Desktop, DAX
I need to help build a control column that finds a bug.
I have three columns: "SN" - serien nr. Data type: text, "MTH" Type data: Whole Number and "Date" Data type: Date.
Each SN has x Mth. Every Mth has just one date.
For each SN, it is true that it can not have more Mth at an earlier date.
Example:
I solved it only by counting the help tables in Query Editor, which took a lot of performance.
I was able to achieve this using the following calculated column:
Control =
VAR BugSN = Bug[SN]
VAR BugMth = Bug[Mth]
VAR BugDate = Bug[Date]
RETURN CALCULATE(
MAX(Bug[Date]),
ALL(Bug), Bug[SN] = BugSN, Bug[Mth] = BugMth
) = BugDate
What this says is that if the date in that row is the max for that SN and Mth combination, then TRUE otherwise FALSE.
(I named the table Bug, but you'll need to replace that with whatever your table name is.)
I use jquery datepicker (v1.8.20) with the date format set to 'D MM d' which looks like: 'Wed September 12'. When I select different year than the current one from a calendar, the getDate method returns me current year. Moreover, when I open calendar again, both selected day and month are preserved, but the year is changed for the current one. Generally it looks like year is set to current one when the date format does not contain it. Any idea how to fix that?
Datepicker stores value only in input element, so if you don't have a year in format string, datepicker merely doesn't store it. Here one of jquery.ui developers says, that this is not a bug and "Datepicker is only designed to pick a full date".
Anyway, I had the same problem in my project, and solved it by ugly trick, that forces datepicker to store full date:
(function($) {
$.datepicker._selectDateParent = $.datepicker._selectDate;
$.datepicker._adjustInstDateParent = $.datepicker._adjustInstDate;
$.datepicker._adjustInstDate = function(inst, offset, period) {
var fullDate = inst.input.data('fullDate');
if(fullDate && !period) {
inst.drawYear = inst.currentYear = fullDate.getFullYear();
}
this._adjustInstDateParent(inst, offset, period);
};
$.datepicker._selectDate = function(id, dateStr) {
var target = $(id);
var inst = this._getInst(target[0]);
var date = this._daylightSavingAdjust(new Date(inst.currentYear, inst.currentMonth, inst.currentDay));
inst.input.data('fullDate', date);
this._selectDateParent(id, dateStr);
}
})(jQuery);
I've tested it only with datepicker 1.9.0+ and I'm not sure, that this is a good solution, but it works for me :)
I have a Column Chart with an x-axis value which is a date. This chart worked this morning but is suddenly broken and displaying "Bars series with value domain axis is not supported." as an error message. The website in question hasn't been updated in weeks.
My DataTable construction code looks like:
var data= new google.visualization.DataTable({
"cols":[{"label":"Date","type":"date"},{"label":"New Users","type":"number"}],
"rows":[{"c":[{"v":new Date(1325656800000),"f":null},{"v":1355,"f":null}]}]
});
What can I do to my code to fix this?
It's not a bug. Google Visualisation API has changed.
At http://code.google.com/apis/chart/interactive/docs/customizing_axes.html#Help they post some solutions to this problem. Using option:
strictFirstColumnType: false
can only be used as a temporary solution. Google says:
However, please bare in mind that this option is only available for limited time and will be removed in the near future.
The recommended solution is that you change your Date fields on x axis to String. I've achieved this by using formatter before adding value to the DateTable object.
var formatterMoney = new google.visualization.NumberFormat({suffix: ' zł', decimalSymbol: ',', groupingSymbol: ' '});
var formatterDate = new google.visualization.DateFormat({pattern: 'dd.MM.yyyy'});
var data = new google.visualization.DataTable();
data.addColumn('string', 'order date'); //used to be date field here
data.addColumn('number', 'total amount');
data.addRow([formatterDate.formatValue(new Date('2011-12-20')),971793.93]); //used to be Date object, now is Date formated as String
data.addRow([formatterDate.formatValue(new Date('2011-11-30')),1.0]);
data.addRow([formatterDate.formatValue(new Date('2011-11-17')),1.0]);
data.addRow([formatterDate.formatValue(new Date('2011-10-27')),1.72]);
data.addRow([formatterDate.formatValue(new Date('2011-10-26')),10.27]);
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
formatterMoney.format(data, 1);
chart.draw(data, {width: window.width, height: 400, hAxis: {direction: -1}});
The problem is with the Date fields. I've converted the date field to a String and I'm using a String now. In case you are using formatters, you can format the value before supplying it to the DataTable:
formatter.formatValue(date)
I'm guessing this is a bug; I'll try to file a bug report.