Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Date/Time Issue

Date/Time Issue

Date/Time Issue

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

CODE --> 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?

RE: Date/Time Issue


Quote (Marine1969)

I have tried date ("Y-m-d", $edate)
In case you mean like this :

CODE --> php -a

php > $edate = '11/05/2017';

php > 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 strtotime() too :

CODE --> php -a

php > var_dump(date("Y-m-d", strtotime($edate)));
php shell code:1:
string(10) "2017-11-05" 


RE: Date/Time Issue

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?

RE: Date/Time Issue


Quote (Marine1969)

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

Quote (Marine1969)

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 :


alter table your_table modify your_field time; 
Then you can put '13:30' in it.


RE: Date/Time Issue

Turns out I needed to reboot. Thank you!!!!!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close