Reformat date in PHP - javascript

I have a problem. I've a date input on my site. When the input type date is not supported by the browser, I'm initializing a jQuery datepicker.
The problem is, that the normal date input returns the value like this:
2019-08-23
And the datepicker this way:
26.08.2019
Instead adding a hidden field in the HTML, I want to re-format the received value via PHP to the first format above. So is there a way to build a small function that checks if the format is the datepicker format and which returns the formatted value like 2019-08-26?
I'm receiving the value with $_POST['date'].

Something like this should work:
echo date("Y-m-d", strtotime("26.08.2019"));
Reference: PHP strtotime()

Related

Is there a way to add the current day's date within an email body in dd/mm/yyyy format?

Where I work there is the need to send emails where we need to add a specific code and then the current date on a new line, I have been able to sort out the first aspect using the following:
<button onclick="location.href='mailto:Kofax.AriesNotes#xxxxbank.co.uk?body=NB%0d%0aHMLR%0d%0a';">HMLR</button>
On the third line I want the date to pre fill in dd/mm/yyyy format but am having difficulty working out how to do this.
Instead of inlining the event handler, make a separate function (say buttonClicked) and attach it to onclick. Inside the buttonClicked method, use the Date() constructor to get a date object. Then using the getDate(), getMonth(), and getFullYear() functions, build a date variable in the format you desire. Afterwards, do a string concatenation to add that to the mailto: URL string, and finally point location.href to that.

How to format user input time format in JavaScript?

I have user input field that accepts time value. Here is example of that value: 03:45:15.0 I would like to format this value with JavaScript to format the time like this: 03:35:15 PM. Is there a way to complete this with Vanilla JS?
Thank you.

Netsuite! using freemarker to get the name of the month from a date DD/MM/YYYY doesn't work

Problem
I am working on an email template text whereby I would like to change the date DD/MM/YYYY to MMMM. There are two instances of it in the template. The two instances belong to 2 different date fields however their configuration is the same. Let's say I have date_field1 and date_field2. When I do the following in date_field1 it works fine but in date_field2 it doesn't and I get the following error.
I have checked the type of mydate just to make sure and it is a date. When I just do ?string it works fine and it does contain a date value but with .MMMM, it throws an error. Any help or suggestion will be great.
Code
Working: <#assign mydate1=transaction.date_field1 /> ${mydate1?string.MMMM?lower_case}
Not working: <#assign mydate2=transaction.date_field2 /> ${mydate2?string.MMMM}
Error
If you have an actual date field the format string is like:
<#assign mydate=transaction.date_field2?date["MMMM"]>
And of course there is no field called date_field2 so I assume that label is meant as a simplified example.
Note you can also try:
<#assign mydate=transaction.date_field2?string["MMMM"]>
But I think that was for a more recent version of Freemarker than Netsuite supports.
Finally you can set the overall string to date format which will be in place from the place in your code down to wherever you reset it. I found I had to set it for both date and datetime because some 'date' fields are interpreted by Freemarker as datetime even when they shouldn't be:
<#setting date_format="MMMM">
<#setting datetime_format="MMMM">
${transaction.date_field2}

date string doesn't show up in date input

I have saved date as a string.
for example:
I have object in angularJs called myBirthday.
myBirthday.date="1996-04-04";
and I want to show the date in input in the modal:
<input type="date" ng-model="myBirthday.date" />
The problem is that it's shown dd-mm-yyyy instead of 04-04-1996.
Then When I change the date,close modal and then reopen it,The input shows the correct date.
How can I make it to show the correct date? not dd-mm-yyyy?
I have tried almost every string types of date.
please HELP
You shoud create a Date object instead of a String.
myBirthday.date = new Date(1996, 3, 4);
You could also cast the Date to a String:
date_string = myBirthday.date.toISOString();
It seems date filter called before binding of date or date-format values. date/dateformat is null initially but filter called that's why filter would be giving default format string. And once values are binded properly then everything works perfectly fine

How to set default format date with angular ui bootstrap

I use ui.boostrap for a datepicker,
http://plnkr.co/edit/GfOQmgW85U2aW3YbZO7T?p=preview
I need to format the date like "yyyy/MM/dd" because that's how my RESTapi receives the args.
Applying $filter in angular.
http://docs.angularjs.org/api/ng.filter:date
It seems that the problem was solved, however when I change the date in the datepicker, the format date changes to a format like 2014-01-30T00:58:43.000Z
how can I set default format date with this tool?
Since the date is a JS Date object, you'll have to convert it before sending. You can use the datefilter to parse manually before sending:
var datefilter = $filter('date'),
formattedDate = datefilter($scope.dt, 'yyyy/MM/dd');
See this plunk for an example: http://plnkr.co/edit/EJLDpEojoFnf5QfFt4o6?p=preview
Only alternative I know of, is creating a directive for the value and pushing a function to $parsers like in this example, but that's definitely not easy to combine with the datepicker directive.
I'd suggest to continue using the Date object in JS, and just convert the value before sending to your API.

Categories

Resources