Vue.js - Laravel Populating datetime-local input field - laravel

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.

Related

Can't remove hours and minutes from datatable

I'm trying to get release date field with y-m-d format.. Actually time format (for y-m-d) seems fine but also it gives h:m:s too, I changed time format at server side and removed h:m:s but datatable still shows them
What I get
2012-04-11 00:00:00
What I want
2012-04-11
Released_at field (Metronic theme - json datatable)
{
field: "released_at",
title: "Release Date",
type: "date",
format: "YYYY/MM/DD"
}
time format (I'm using laravel framework)
protected $dateFormat = "Y-m-d";
How do I fix this ?
Datatable accept column type same as mysql type.
You are trying to convert mysql dateTime column to Date in datatable, which is not possible from datatable.
In your code you have declared
format: "YYYY/MM/DD" // but actual type is dateTime as per mysql.So it will append time next to it.
If you are storing only date in mysql then you can change column type to Date, and your problem gets solved.
And if you want to convert string to date in laravel you can follow this post.
Your database column is of type dateTime which, by definition, includes both date and time information. If you want to remove the time at a database level then use the date type instead
$table->date("released_at")->nullable();
If instead of removing the time from the database, you just want to ignore it for certain parts of your application, you can leverage the fact than in Laravel all dates coming from your models are Carbon\Carbon instances, so you could do
$model->releasedAt->format('y-m-d'); // Returns '18-09-11'

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

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

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}.

disable drupal date validation

I have a date field (widget = select list) in a drupal 7 content type, And I want to be able to enter a date like 2012/2/31 without any validation error?
what can I do?
The problem is 2012/2/31 is not a date, it's just a text string that resembles the formatting of a real date.
If you don't want to use proper, valid dates, then you simply shouldn't be using a date field. I'd advise adding a text field instead and then using the Field validation module to define a pattern to test the input against. That way you can accept any kind of string that resembles a date, not just real dates.
You can use date module, it provides you a date picker widget and output will be same as 2012/2/31, either you have to use textfield widget.
Date Module

Resources