ngx-mydatepicker is formatted as jsdate and doesn't format back to normal date angular 4 - angular-reactive-forms

I am using ngx-mydatepicker in my angular 4 application with reactive forms. I am binding date field to input field from rest api which is in the format "OrderDate": "2018-07-03T15:58:20.183". This doesn't populate date in input field directly so we need to convert it to jsdate as suggested in this post githubissue as in the below code snippet
'OrderDate': [{jsdate: new Date(data.OrderDate)}, Validators.required],
Now the date appears in the input field as expected. Now the actual problem is while submitting the form the date is coming in this format as in the below screen shot which is not accepted by rest api. So I need to convert it back to the api accepted format, how do I do it and my form contains more than 40 fields where am posting the form directly to api, so if I need to format the date I should explicitly again edit the form data before sending it to api. Is there a way that the date will format directly without explicit formatting. If there is no way then how to format back to normal date format.
Thanks in advance

Try the format using toISOString,
new Date(field).toISOString()
Reference

Related

Vue.js - Laravel Populating datetime-local input field

I'm trying to populate my Vue.js Template to update a model
<input type="datetime-local" name="start_time" v-model="start_time">
Having issues pre filling the date-time field
start_time: "2020-02-12 22:00:00"
this is the data that i receive from api and i'm directly assigning it to my start_time variable
Just adding to the answer
use format
'YYYY-MM-DDTHH:mm'
otherwise there will be an issue with AM and PM
According to the MDN web docs for datetime-local the format should be yyyy-mm-ddThh:mm. Therefore you'll need to update the value of your data property to be:
2020-02-12T22:00
Since you've using moment you can format the initial date with:
moment(dateString).format('YYYY-MM-DDThh:mm')
Replace dateString with the actual date string or property that contains the date string.

Dynamics 365, Entity View, format date field to "Month Year"

I am working on an entity view that displays billing records with associated date. This date field needs to be displayed as "Month - Year". Unfortunately, I am not able to find a way to format this date field outside of modifying the entity and even then, I only have the option for date only or date and time.
I have noticed that I can select the field and click on Change Properties. There I have "Web Resource" and Function Name. I have tried creating a web resource with a function that returns some data. Set everything up, saved and published. This function is not even found in dev tools. Only examples that I have for it are dealing with using this method for icons:https://www.c-sharpcorner.com/article/view-customization-with-javascript-in-dynamics-365/
In another example the suggestion is to use calculated fields, but this would cause me to lose date sorting and filtering on the form.
That view-based JavaScript seems to be to choose an icon. I'm not sure it would allow you to reformat actual data in the view. And if you're looking for assistance with trying to do that, you'd probably get more help if you posted the code.
Besides the JavaScript approach, you might want to think about creating a separate text field to hold the "Month - Year" value. Then you could use a workflow, plugin, or JavaScript to populate it when the datetime field changes.
One of the free workflow tool packages (Jason Lattimer's, Aiden Kaskela's, or Andrew Butenko's) probably has the ability to parse the date so you can format the month and year, and store the string in the separate field. This would be a no-code option.
Alternatively, you could write a plugin to reformat the datetime values and register it on the RetrieveMultiple message of the entity.
I'd probably go with a separate field and an off-the-shelf workflow utility to populate it.
There are several ways:
1. Setting->Administration->System Setting->Format->Customize,
2. http://prntscr.com/ph42nc,
3. or use on load with js to change date format more on this subject here: How to change date format in JavaScript

400 - Bad Request while saving Date Only field in CRM using Web API

I am using Microsoft Dynamics 365 Web API approach to interacting with CRM data.
Here I want to update the field with type: DATE and TIME.
Date value I am passing in the request body is as below:
"packfirstday":"1-15-2018"
Except for above, I have also tried with DateTime and with different date formats.
e.g.
mm-dd-yyyy
m-dd-yyyy
mm/dd/yyyy
yyyy/mm/dd
yyyy-mm-dd
PS: I try to post without date field it is saving details successfully.
The problem is not with the code, the simple misunderstanding.
There are 2 components namely Behavior & Format. You have Format set as 'Date only' not the Behavior. Behavior decides the Database terms whereas Format is used for displaying datepicker controls in Form.
So when you set the field in web api with only date part - the CRM database expects time part also.
Either set behavior also as date only, so this will work:
"packfirstday":"2018-01-15" //YYYY-mm-dd format
Or change your code to pass time part also:
"packfirstday":"2018-01-15T11:10:00.000Z" //UTC offset
Since user local behavior still expects the time part.

Date format handling in Spring MVC

HI I have a problem in my current Spring +JPA project. My entity object and bean object for web page are same.
From web page using jquery i am reading date in (dd-mon-yyyy) format from screen and saving it to database. The field is of Date type in my bean class.
During update i am fetching values from database and displaying the same in web page. But this time the date format has chnaged to different fromat(yyyy/mm/dd) on screen.
So while saving again i am getting error, as the date format has been changed and i am unable to parse the value received form screen.
So is there any proper way to handle this situation.
I assume that you are storing the dates in database as a DATE or DATETIME type. If so, the value should be a Date object in Java. In order to output the date value as dd-mon-yyyy, you will need to use SimpleDateFormat to convert the date object into a string representation in your desired format:
new SimpleDateFormat("dd-MMM-yyyy").format(date);
An additional note: for an internal-only API, it doesn't matter what format you choose as long as you are consistent everywhere. But if you are creating something that could one day be exposed publicly, I would suggest that you send/receive date and time value in the ISO8601 format: yyyy-MM-ddTHH:mm:ssZ. This format is understood by everyone everywhere.
Update:
Based on your comment, I would say add a new method to your bean class:
private DateFormat dateformat = new SimpleDateFormat("dd-MMM-yyyy");
public String getFromDateString() {
return dateformat.format(fromDate);
}
And then in your JSP, call ${bean.fromDateString}.

Facebook Graph API feed order by created_time

I`m using query like
me/feed?fields=id,status_type,link,full_picture,type,description,name&since=2014-08-28T11:24:13&limit=30
But API response contains latest post at top
I want to see the post that created after 2014-08-28
What can I do for it?
As https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#paging outlines, you have to use Unix timestamps for the since parameter:
since : A Unix timestamp or strtotime data value that points to the start of the range of time-based data.

Resources