I have tried many times to store the exact date which I have selected. But when saving, it will take the previous date. I have tested in many ways, the angular file will pass the same selected date. When the sql query is executed, then it will take the incorrect date. can anyone please help me to solve this?
Below is my code. html code:
<td class="data_field">
<input class="form-control" type="date" name="date_main_domain" ng-model="domain.date_main_domain" id="date_main_domain" required value="{{domain.date_main_domain}}">
</td>
sql query:
$database->execute( "UPDATE domain_information SET date_main_domain='$dateMainDomain' WHERE id=$domainId" );
You need a valid date for the database to accept it, format your date object
function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
return [year, month, day].join('-');
}
// date object to save
var date = new Date(formatDate($scope.domain.date_main_domain));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With