I am using a kendo grid with a date editor template. I am trying to format date using the client template.
The current output is: 'Fri Jul 13 2018 00:00:00 GMT-0400 (Eastern Daylight Time)'.
How do I get it into 'yyyy-MM-dd' format?
below is the column code
columns.Bound(c => c.NewEffectiveDate)
.ClientTemplate("#if(NewEffectiveDate === null){# #}else{# #=kendo.toString(NewEffectiveDate, 'yyyy-MM-dd')# #}#")
.EditorTemplateName("Date")
.Title("New Effective Date")
.Width(100)
.HtmlAttributes(new
{
style = "text-align: center;"
});
Can u try
kendo.toString(new Date(2000, 10, 6), "d") -> 10/6/2000
We need to define the format specifier for particular pattern.
The "d" specifier renders a short date pattern ("M/d/yyyy" for en-US), as shown above.
Related
Hello I am new to FTL Code and I am trying to re format a date based on how a locale would display it.
The error I am getting: (Please look below for more info of the result we want)
The string doesn't match the expected date/time/date-time format. The string to parse was: "août 26, 2035". The expected format was: "MM dd, yyyy".
The nested reason given follows:
Unparseable date: "août 26, 2035"
<#assign locale = userPreferences.getLanguage()>
my locale ${locale}<br>
<#if locale = "en_AU">
original = ${couponData.expiration}<br>
<#assign expiryDate = couponData.expiration?date("dd MM, yyyy")?string("dd MM yyyy")>
format ${expiryDate} <br>
${sys.declare("dateMonthYear", expiryDate)}
<#elseif locale = "en_GB">
original = ${couponData.expiration}<br>
<#assign expiryDate = couponData.expiration?date("MM dd, yyyy")?string("dd MM yyyy")>
format ${expiryDate} <br>
${sys.declare("dateMonthYear", expiryDate)}
<#elseif locale = "fr_CA">
original = ${couponData.expiration}<br>
<#assign expiryDate = couponData.expiration?date("MMM dd, yyyy")?string("dd MM. yyyy")>
format ${expiryDate} <br>
${sys.declare("dateMonthYear", expiryDate)}
<#else>
${sys.declare("dateMonthYear", "${couponData.expiration}")}
</#if>
CA_FR Source:
Ends Jul 31, 2022
Actual:
Expire le juil. 31, 2022
Expected:
Expire le 31 juil. 2022
EN_GB Source:
Ends Jul 31, 2022.
Actual:
Ends Jul 31, 2022.
Expected:
Ends 31 Jul 2022.
enter code here
EN_AU Source:
Ends Jul 31, 2022.
Actual:
Ends 31 Jul, 2022.
Expected:
Ends 31 Jul 2022.
I was able to solve my issue:
it seems in the string MM-DD-YY will format into something like 01/01/2022
Where as was proving three MMM-DD-YYYY will give me Jan 01, 2022
I can manipulate the dateformat inside the string also
<#setting locale="fr">
<#assign expirationDate = expiration?number_to_date?string("yyyy MMM. dd")>
I'm trying to compare one date value (ie. base value) with all other date values on a page and based on the difference between these days, I want to execute other commands.
Well, in the above UI, the base value is 11 Jul 2021 (Departure date in the first list) and other date values are 12 Jul 2021, 20 Jul 2021, 27 Jul 2021, 3 Aug 2021 and so on (Arrival dates from 2nd list onwards).
Now, I had to delete the all list(s) where the date difference between the base value and particular list is less than 15 days.
In this case, 12 Jul 2021, 20 Jul 2021 had to be deleted and all lists from 27 Jul 2021, 3 Aug 2021 and so on should be untouched as in the below picture.
So far, I have captured the value of the base value and came up with logic to compare it with another date value but I am not sure how I can save the 2nd and further date value(s) to a variable in order to compare with the base value.
{
cy.get("[data-test='departureTime']")
.eq(0)
.then((date) => {
const depDate_FirstPort = new Date(date.text());
cy.log(depDate_FirstPort.toISOString()); //2021-07-11T19:00:00.000Z
// const arrDate_SecondPort = new Date(cy.get('[data-test="arrivalTime"]').eq(1).invoke('text'));
// Since the above approach does not work, hard coding now.
const arrDate_SecondPort = new Date("22 Jul 2021 12:01")
cy.log(arrDate_SecondPort.toISOString()); //2021-07-22T10:01:00.000Z
cy.getDifferenceBetweenDates(depDate_FirstPort,arrDate_SecondPort).then((dif)=>{
if(dif < 16) {
cy.log("delete the port entry");
//do something
}
});
});
}
Cypress Command:
Cypress.Commands.add("getDifferenceBetweenDates", (Date1, Date2) => {
var diff_times = Math.abs(Date1.getTime() - Date2.getTime());
var diff_days = Math.ceil(diff_times / (1000 * 3600 * 24));
cy.log(diff_days) //11
})
Also, curious to know a possible approach to iterate all list falls under the 'to be deleted list' (12 Jul 2021, 20 Jul 2021) based on the condition mentioned above.
The iterative approach you have is ok, but you need to repeat the code you have for the first date to get the subsequent dates.
So, this bit but changing the index
cy.get("[data-test='departureTime']")
.eq(0) // 1,2,3 etc
.then((date) => {
A different approach is to filter the whole set,
const dayjs = require('dayjs') // replaces Cypress.moment
// first install with
// yarn add -D dayjs
it('finds the skipped ports', () => {
// helper func with format specific to this website
const toDate = (el) => dayjs(el.innerText, 'D MMM YYYY HH:mm')
cy.get("[data-test='departureTime']")
.then($departures => {
const departures = [...$departures] // convert jQuery object to an array
const first = toDate(departures[0]);
const cutoff = first.add(15, 'day')
const nextPorts = departures.slice(1) // all but the first
const skipPorts = nextPorts.filter(port => toDate(port).isBefore(cutoff))
expect(skipPorts.length).to.eq(2)
expect(skipPorts[0].innerText).to.eq('12 Jul 2021 14:02')
expect(skipPorts[1].innerText).to.eq('21 Jul 2021 04:00')
})
})
I'm not clear about your goal, but if you are going to actually delete the skipPorts from the page instead of just testing them, you should be wary of the DOM list changing as you do so.
Deleting from the list you have recently queried with cy.get("[data-test='departureTime']") would cause the internal subject to become invalid, and you might get "detached from DOM" errors or delete the wrong item.
I'm using momentjs with timezone.
I've converted date to i18n using moment.locale('pt');
Now I want to get timestamp of the date. I get date value as converted i18n date, i.e. Ago 14 2018 22:00
I tried with moment("Ago 14 2018 22:00").tz("Asia/Calcutta").unix() => this is returing NaN
But this is working => moment("Aug 14 2018 22:00").tz("Asia/Calcutta").unix()
So how can I get timestamp of converted i18n date??
Here is fiddle of the problem : http://jsfiddle.net/uq99udc9/10265/
You need to first specify a locale as per momentJS documentation.
You also need to make sure you have that locale and if not import it.
Here is an example:
moment.locale('fr')
var date = moment("14 août 2018 10:37", "DD MMM YYYY hh:mm", "fr").format('LLL')
console.log(date);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/locale/fr.js" charset="UTF-8"></script>
Is it possible to validate date input to name of day followed by a comma, then the day of the month, then the month and finally the year in full? eg Sunday, 31 December 2017
You can use the date_format validation rule with a custom defined date format string:
'some_date' => 'date_format:"l, j F Y"',
Yes, but you have to make your own custom validation function :)
More details you can find here:
custom validator
You can easily download Carbon package from packagist.org
and then use every format you want.
For example :
$dt = Carbon::create(1975, 12, 25, 14, 15, 16);
echo $dt->toDayDateTimeString(); // Thu, Dec 25, 1975 2:15 PM
You can Use Core PHP like this:
$date = '2018-01-01';
echo date('l, j F Y', strtotime($date));
I've got a bunch of user-inputted dates and times like so:
date = "01:00pm 06/03/2015"
I'm trying to submit them to a datetime column in a database, and I'm trying to systemize them like this:
DateTime.strptime(date, '%m/%d/%Y %H:%M')
But I consistently get an invalid date error. What am I doing wrong? If I submit the string without strptime the record will save but it sometimes gets the date wrong.
Also, how can I append a timezone to a DateTime object?
Edit:
So .to_datetime and DateTime.parse(date) work for the date string and fail for date2. What's going on?
date2 = "03:30pm 05/28/2015"
Try using to_datetime:
date.to_datetime
# => Fri, 06 Mar 2015 13:00:00 +0000
Also if you read the documentation for DateTime#strptime, here. It states:
Parses the given representation of date and time with the given
template, and creates a date object.
Its important to note that the template sequence must match to that of input string sequence, which don't in your case - leading to error.
Update
Using to_datetime over second example will generate
ArgumentError: invalid date
This is because it expects the date to be in dd-mm-yy format. Same error will be raised for DateTime.parse as to_datetime is nothing but an api for the later. You should use strptime in-case of non-standard custom date formats. Here:
date2 = "03:30pm 05/28/2015"
DateTime.strptime(date2, "%I:%M%p %m/%d/%Y")
# => Thu, 28 May 2015 15:30:00 +0000
date = "01:00pm 06/03/2015"
DateTime.parse(date)
=> Fri, 06 Mar 2015 13:00:00 +0000
You haven't got your parameters in the correct order.
DateTime.strptime(date, '%H:%M%p %m/%d/%Y')
You'll also need to add %p for the am/pm suffix