CSmith1128 Posted February 9, 2008 Share Posted February 9, 2008 Hello.. I have a pretty simple question probably.. but for some reason I cannot think right now and cannot figure it out... I need to convert this: 1:11 PM to the mysql date format. So the format that CURDATE() is in i need it converted to. First, what format is CURDATE() in? Just for reference. And second, how would I convert it? I am given the hour from 1 to 12, minutes, and AM or PM. Thanks! -Chris Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 9, 2008 Share Posted February 9, 2008 Try: http://ca.php.net/manual/en/function.date.php CURDATE gets the timestamp of the current date. http://www.gizmola.com/blog/archives/51-Exploring-Mysql-CURDATE-and-NOW.-The-same-but-different..html Quote Link to comment Share on other sites More sharing options...
CSmith1128 Posted February 9, 2008 Author Share Posted February 9, 2008 Yea I looked at the date function. Can I tell it 1:11 PM and have it converted to a timestamp? How would I do that. I already have the time, I just need it converted. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 9, 2008 Share Posted February 9, 2008 You would make the Mysql Row a TIMESTAMP field, and insert the DATE in there. Quote Link to comment Share on other sites More sharing options...
CSmith1128 Posted February 9, 2008 Author Share Posted February 9, 2008 And I dont have to worry about converting it? I have a form where a visitor can enter a time. There's an hour, minute, and am/pm drop down selector so they can choose the time. So I get the hour, minute, and am/pm separately. The format I get it in isn't in the timestamp format. The mysql field is in the TIME format. So I have to convert the hour, minute, and am/pm to whatever format CURTIME() is in. (sorry, I said CURDATE in my first post) Is there a function to do that? Quote Link to comment Share on other sites More sharing options...
CSmith1128 Posted February 9, 2008 Author Share Posted February 9, 2008 if($this_time_ampm == "PM") { if($this_time_hour != 12) { $this_time_hour = $this_time_hour + 12; } } else { if($this_time_hour == 12) { $this_time_hour = "00"; } } how does that look? Quote Link to comment Share on other sites More sharing options...
CSmith1128 Posted February 9, 2008 Author Share Posted February 9, 2008 oops.. forgot a part... $this_time = $this_time_hour . ":" . $this_time_minute . ":" . "00"; add that below. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 9, 2008 Share Posted February 9, 2008 Is it me or am I missing something? But I don't think you can convert a time into a date. you can convert date time into a date or a time, by just chopping off one or the other. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 9, 2008 Share Posted February 9, 2008 Use a combination of the strtotime() and date() function: <?php $time = '1:11 PM'; $mysql_time = date('H:i:00',strtotime(date('Y-m-d') . ' ' . $time)); echo $mysql_time; // show what's there ?> Ken Quote Link to comment Share on other sites More sharing options...
CSmith1128 Posted February 10, 2008 Author Share Posted February 10, 2008 yes. perfect.. thats what I was looking for.. THANKS! Quote Link to comment Share on other sites More sharing options...
Barand Posted February 11, 2008 Share Posted February 11, 2008 if you want MySQL DATETIME format <?php $time = '1:11 PM'; $mysql_time = date('Y-m-d H:i:s', strtotime($time)); echo $mysql_time; // ---> 2008-02-11 13:11:00 ?> Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 11, 2008 Share Posted February 11, 2008 Why don't you just google your answers? I found all your answers just by google'ing. If you need a SCRIPT that you have written help with, then you come to this section. Search before you ask most of them, because there is a large chapter in php and mysql regarding TIMESTAMPS and DATES,. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 11, 2008 Share Posted February 11, 2008 Then we can can shut down this site since most problems people have have probably been encountered before anyway by someone else. It's all in Google - you don't need us. Just find that large chapter in php and mysql. @phpSensei, can I quote you next time you post a question? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 11, 2008 Share Posted February 11, 2008 Then we can can shut down this site since most problems people have have probably been encountered before anyway by someone else. It's all in Google - you don't need us. Just find that large chapter in php and mysql. @phpSensei, can I quote you next time you post a question? ??? What I ment If you need a SCRIPT that you have written help with, then you come to this section. This is a common DATE question which has been answered many times before. You can refer to this site's search tool to answer your question or google it. By "Large" chapter I ment was a whole lot of info you can just fly by in the manual and find the answer. Also, PHPfreaks, dispite the name, isn't just about PHP questions, or googl'ing all of them. People mostly want to create custom scripts and so we help them. But this is a function or one category question, so its best off google'd. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 11, 2008 Share Posted February 11, 2008 phpSensei, You might want to read this ropic http://www.phpfreaks.com/forums/index.php/topic,166260.0.html Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 11, 2008 Share Posted February 11, 2008 phpSensei, You might want to read this ropic http://www.phpfreaks.com/forums/index.php/topic,166260.0.html Back in my Noob Days thankyou for that topic, but thats just my point. I actually didnt know how to ALTER a Mysql Table either... You told me to look at the manual dude, but it was a very short search I did, and found the answer in no time. Just like this case... Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 11, 2008 Share Posted February 11, 2008 Ill shut my yap Barand, Ill just help around haha Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.