Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date/Time Issue 1

Status
Not open for further replies.

Marine1969

IS-IT--Management
Mar 5, 2015
60
0
0
US
I have been all over the internet and tried numerous options to get a date to save. I have 2 date and 1 time field I am trying to change in a mysql table. My data I change to 11/17/2017 but the code changes it to 12/31/1969. Everything I found on on the internet was for using the current system date but I am passing a field to record maintenance page and have changed all 3 fields in the db to be datetime.

edate = 11/05/2017
sdate = 11/17/2017
myid = 1

PHP:
$str = "Update mytable Set edate = :edate, sdate = :sdate, stime = :stime Where id = :myid";

$stmt = $conn->prepare($str); 
$stmt->bindParam(':edate', $_POST['edate'], PDO::PARAM_STR); 
$stmt->bindParam(':sdate', $_POST['sdate'], PDO::PARAM_STR); 
$stmt->bindParam(':myid', $_POST['myid'], PDO::PARAM_STR);

I have tried date ("Y-m-d", $edate) and many other variations. I also had the fields originally set to Date and Time but have not done much with the Time field, figured I would concentrate on the Date fields first. Does anyone have any ideas?
 
Hi

Marine1969 said:
I have tried date ("Y-m-d", $edate)
In case you mean like this :
Code:
[blue]php >[/blue] $edate = '11/05/2017';

[blue]php >[/blue] var_dump(date("Y-m-d", $edate));
PHP Notice:  A non well formed numeric value encountered in php shell code on line 1
PHP Stack trace:
PHP   1. {main}() php shell code:0
PHP   2. date() php shell code:1
php shell code:1:
string(10) "1970-01-01"
Then try to involve [tt]strtotime()[/tt] too :
Code:
[blue]php >[/blue] var_dump(date("Y-m-d", strtotime($edate)));
php shell code:1:
string(10) "2017-11-05"


Feherke.
feherke.github.io
 
Awesome! That worked for the date fields. I tried to modify for the time but that did not work. I have field set as Datetime but only need the time from this field. The current data residing there is 2017-11-28 13:30:00 and when I want to delete it I cannot nor can I just save the time. IE. What I want to save in the field is simply 13:30. I tried to change the data type to TIME and it will not let me now. Suggestions?
 
Hi

Marine1969 said:
What I want to save in the field is simply 13:30.
As far as know, that is not possible in any SQL.

Marine1969 said:
I tried to change the data type to TIME and it will not let me now.
You mean, to change the database column type ? That should work. You change it with :
Code:
[b]alter table[/b] your_table [b]modify[/b] your_field [maroon]time[/maroon][teal];[/teal]
Then you can put '13:30' in it.


Feherke.
feherke.github.io
 
Turns out I needed to reboot. Thank you!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top