Date not getting entered in mysql(0000-00-00) using php [duplicate] - php

This question already has answers here:
Php/Mysql date saved as '0000-00-00'
(5 answers)
Closed 6 years ago.
$dat=date("Y-m-d");
This is how date is being fetched in PHP
insert into gd_purchase(Product_Model,Purchase_Date,Purchase_Quantity) values('22P413',2016-12-27,20)
When above query is fired date is entered as 0000-00-00 in mysql

You need to wrap the date value with single quotes like this:
insert into gd_purchase(Product_Model,Purchase_Date,Purchase_Quantity)
values('22P413','2016-12-27',20)

you need to add date part in quotes:
insert into gd_purchase(Product_Model,Purchase_Date,Purchase_Quantity) values('22P413','2016-12-27',20)

Related

Change type of date in html table - php mysql [duplicate]

This question already has answers here:
Convert from MySQL datetime to another format with PHP
(18 answers)
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
I need some help with converting the date to dd/mm/YYYY.
I have this code to display my date in a html table from a mysql database
echo "<td>".$zeile['datumFahrt']."</td>";
Can I convert it in this line so the format will be dd/mm/YYYY instead of YYYY/mm/dd?
Sure you can, first you need to convert it to timestamp and then format it:
date("d/m/Y", strtotime($zeile['datumFahrt']))

How do I get TIMESTAMP whenever I add data into MySQL using PHP? [duplicate]

This question already has answers here:
MySQL auto-store datetime for each row
(7 answers)
Closed 7 years ago.
How can I get timestamp when I add data using PHP in MySQL?
You can set Default value for your column is: CURRENT_TIMESTAMP so when new record be added it have get current timestamp on your server by automaticly.

Need to convert a string(time) in sql to real date in php [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Converting a UNIX Timestamp to Formatted Date String
(10 answers)
Closed 7 years ago.
I have a table with a time (int 4) where is stored time ex:1506201203
That would be:
year-mo-da-hh-mm
2015-06-20-12-03
I need a php script to get the time and display it correctly ..
A bit of help ?
You can use from_unixtime.
FROM_UNIXTIME(column_name, '%Y-%m-%d') in your MySQL query.
Or you can just use date function.
date('Y-m-d-h-m', $n['date']).

PHP Date compare with sql [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
how to use DATE FORMAT in my query?
I have a date from form post as 09-23-2012 and in my sql database i save date with datetime format like 2012-09-23 23:11:13
I want to create a query to compare these two date.
These two date should equal.
Try DATE_FORMAT:
WHERE DATE_FORMAT(the_field, '%Y-%m-%d') = CAST(:yourInput AS DATE)
Or something similar

PHP date time and mysql [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Change date format (in DB or output) to dd/mm/yyyy - PHP MySQL
PHP - Convert to date format dd/mm/yyyy
mysql saves my date and times like this...
2011-08-31 08:48:40
And when I echo them from the database this is how they appear, how can I get them to a universal format like m/d/y...
Or does it not matter if the mysql row is not a DATE_TIME and just VARCHAR and insert it into the database how I want it??
Thanks...
Do it in PHP:
date("m/d/Y", strtotime('2011-08-31 08:48:40'));
Or do it in MySQL:
SELECT DATE_FORMAT('2011-08-31 08:48:40','%m/%d/%Y')
Of course you won't use hardcoded values in your code. You'll use the column name for MySQL or the retrieved column value, that's probably an element in an array, in PHP.
This post is previously answered:
Convert to date format dd/mm/yyyy
Regards

Categories