Herein, a textfield format 2018-05-22 00:00:00 which for dateTime columns in my DB. I am trying to make it two textfield without change into my table wherein one is for date(date-picker) and another is for time.
<div class="form-group col-lg-5">
{!! Form::label('tradedate', 'Traded date:') !!}
<div class=" input-append date form_datetime" data-date="{{date('Y-m-d H:i:s')}}" data-date-format="dd MM yyyy - HH:ii p" data-link-field="dtp_input1">
<input size="16" type="text" value="" readonly class="form-control">
<span class="add-on"><i class="icon-remove"></i></span>
<span class="add-on"><i class="icon-th"></i></span>
</div>
<input type="hidden" id="dtp_input1" value="" name="tradedate" />
</div>
I think issue is that you are not using any sort of function for your date-date-format attribute.
<div class=" input-append date form_datetime" data-date="{{date('Y-m-d H:i:s')}}" data-date-format="{{date('dd MM yyyy - HH:ii p')}}" data-link-field="dtp_input1">
Just for information in laravel you can use Carbon to deal with date and times. We can do date logic very easily using it. Link below: https://carbon.nesbot.com
Hope , it helps...thanks..cheers.
Related
While performing the edit operation using angular 13, I'm using HTML input type date. When fetching a date from the database, it is not showing the date in the textbox. Kindly help me.
update-movie.component.html
<div class="mb-2">
<label>Release Date</label>
<input type="date" name="releaseDate" class="form-control" [(ngModel)]="movieService.movieData.releaseDate"
#releaseDate="ngModel" [value]=movieService.movieData.releaseDate required
[class.is-invalid]="releaseDate.invalid && releaseDate.touched">
</div>```
I found the answer, instead of [value] I used [ngModel] and applied date pipe.
<label>Release Date</label>
<input type="date" name="releaseDate" class="form-control" [(ngModel)]="movieService.movieData.releaseDate"
#releaseDate="ngModel" [ngModel]="movieService.movieData.releaseDate | date : 'yyyy-MM-dd'" required
[class.is-invalid]="releaseDate.invalid && releaseDate.touched">
</div>
I am trying to add a check in my form to check if the End Date is less than the Starting Date it should throw an error which is not working. Don't know whats the issue here.
my .html code is as follows:
<label class="col-md-2 form-control-label">Event Starting Date</label>
<div class="col-md-4">
<input class="validate" #startdate="ngModel" [(ngModel)]="input.event_starting_date" name="startdate" type="date" placeholder="Event Starting Date" class="form-control" required>
<div class="alert alert-danger" *ngIf="startdate.touched && !startdate.valid">Starting Date is required!</div>
</div>
<label class="col-md-2 form-control-label">Event Ending Date</label>
<div class="col-md-4">
<input class="validate" #enddate="ngModel" [(ngModel)]="input.event_ending_date" name="enddate" type="date" placeholder="Event Ending Date" class="form-control" required>
<div class="alert alert-danger" *ngIf="enddate.touched && !enddate.valid">Ending Date is required!</div>
<div class="alert alert-danger" *ngIf="enddate<startdate">Ending Date Must be greater than Starting Date!</div>
The end- and startdate are put in a model like this:
date = {
year: '',
month: '',
day: ''
};
Have you tried comparing every different property of both date models? I don't think you can compare both models directly to each other since they both have their own underlying properties.
i m trying to insert date in mysql table using CI
my code for the datepicker is :
<div class="well well-lg">
<div class="col-md-6 input-group">
<input type="text" name="datep" value="<?php echo $this->input->post('datep'); ?>" class="form-control datep" id="datep" placeholder="Saisissez la date de parution">
<label class="input-group-addon btn" for="datep">
<span class="glyphicon glyphicon-calendar"></span>
</label>
</div>
</div>
the dateformat in datepicker config is : dd-mm-yyyy
and displayed like that dd-mm-yyyy
the problem is when i m trying to insert it in the table
this yhe code in the MODEL file :
function add_livre($params)
{
$this->db->insert('livre',$params);
return $this->db->insert_id();
}
always i have 0000-00-00 value for this date
I have a problem with Thymeleaf date format when I send a date. The HTML shows the date correctly within a h3 tag but not inside the code of the datepicker and I can not understand why....
<div>
<label for="birthdate" th:text="#{editprofile.about4.birthdate}">Birth date</label>
<label class="input">
<i class="icon-append fa fa-calendar"></i>
<input type="date" name="date" id="birthdate" class="form-control margin-bottom-20" th:value="${#dates.format(profile2about2th.birthdate,'yyyy/MM/dd')}" th:field="*{birthdate}">
</input>
</label>
<h3 th:text="${#dates.format(profile2about2th.birthdate,'yyyy/MM/dd')}"></h3>
</div>
why it shows the date with hours in one place and correctly in the other...... input type="date" name="birthdate" id="birthdate" class="form-control margin-bottom-20" value="1932-10-10 00:00:00.0"
Thanks
th:field and th:value shouldn't be used on the same tag. (th:field sets the name, id and value attributes of the tag it is on.) You'll see that you would get the correct formatting if you left off th:field, but then the form wouldn't submit correctly. In my opinion, the way to fix this is to:
Add an InitBinder method to your controller, like this:
#Controller
public class WhateverController {
.
.
.
#InitBinder
public void initBinder (WebDataBinder binder) {
binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy/MM/dd"), true));
}
.
.
.
}
Remove the th:value. Your HTML should look like this:
<div>
<label for="birthdate" th:text="#{editprofile.about4.birthdate}">Birth date</label>
<label class="input">
<i class="icon-append fa fa-calendar"></i>
<input type="date" name="date" id="birthdate" class="form-control margin-bottom-20" th:field="*{birthdate}" />
</label>
<h3 th:text="${#dates.format(profile2about2th.birthdate,'yyyy/MM/dd')}"></h3>
</div>
There are ways to add global binders as well, if you want this to work for your entire application and not just that one controller.
Ensure that the date passed in as value (in this case birthdate) is of this format:
yyyy-mm-dd
and NOT in the date picker's format mm/dd/yyyy
Read more here.
I was playing around with this http://www.phpform.org/ to create a form.
One of form html is the following.
I am not sure what kind of type I should use it for HH, MM and AM/PM.
Should I use TINYINT with 2 length for HH, MM and VARCHAR with 2 length for AM/PM?
Should I have separate field for each?
...
...
<li id="li_1" >
<label class="description" for="element_1">Time </label>
<span>
<input id="element_1_1" name="element_1_1" class="element text " size="2" type="text" maxlength="2" value=""/> :
<label>HH</label>
</span>
<span>
<input id="element_1_2" name="element_1_2" class="element text " size="2" type="text" maxlength="2" value=""/> :
<label>MM</label>
</span>
<span>
<input id="element_1_3" name="element_1_3" class="element text " size="2" type="text" maxlength="2" value=""/>
<label>SS</label>
</span>
<span>
<select class="element select" style="width:4em" id="element_1_4" name="element_1_4">
<option value="AM" >AM</option>
<option value="PM" >PM</option>
</select>
<label>AM/PM</label>
</span>
</li>
Thanks in advance.
Store it as a regular 24 hour HH:MM:SS (the mysql time type). Do the formatting when outputting. You can use TIME_FORMAT() to reformat it into AM/PM format:
mysql> SELECT TIME_FORMAT('22:22:22', '%r');
-> '10:22:22 PM'
The three fields together represent a time. The most appropriate type for this would be TIME. There's no need to keep them separate and it makes your database more complex than it needs to be.