Jump to content

[SOLVED] php and mysql date


ngreenwood6

Recommended Posts

premiso can you help me with that? just a basic example would be great. i hate when people like gevans post stuff like look at this page. I already knew you could store the dates and times like that but that is not how I want them stored. I wish that if people didnt want to help they wouldnt post. thank premiso tho

Link to comment
Share on other sites

Excuse me? You don't want to store in the standard formats that MySQL offer making it extremely easy to convert to and from any format you wish, and also making it a lot easier (and faster) to query the databse with regards to times and dates?

Link to comment
Share on other sites

Basically it would require changing the table type to INT or datetime and using time to update the database.

 

If you want it stored in the DB as MM/DD/YYYY, which I do not know why you would, you would probably need a varchar of 10, but note that does limit your options, where as the timestamp can be pulled out and manipulated using the date function to show seconds, the month, the year, all of the above or some. I would highly suggest changing that table deal. But yea, my 2 cents on that part.

 

To store it as MM/DD/YYYY simply put the timestamp into date like so:

 

$dateFormat = date("m/d/Y");

$sql = "UPDATE tblname SET colDate = '" . $dateFormat . "' WHERE bob=1";

 

Should format the time correctly. I am not sure how to do it in mysql, so if that is your goal I would suggest reading up more on MySQL and Dates.

 

As for the rude comment back to gevans, I would agree with him, reading is your #1 key to finding a solution. He was basically suggesting different ways to manipulate dates in MySQL. I would suggest reading through that page as it will help you out in the long run.

Link to comment
Share on other sites

premiso can you help me with that? just a basic example would be great. i hate when people like gevans post stuff like look at this page. I already knew you could store the dates and times like that but that is not how I want them stored. I wish that if people didnt want to help they wouldnt post. thank premiso tho

 

A lot of 'developers' don't use these resources and it can help you out a lot faster than writing into a forum, I'm not deterring from asking for help where it's needed, but a lot of information is readily available via the right resources such as mysql.com and php.net

Link to comment
Share on other sites

I store my timestamps as int(11) but some people do not like to do that. So first modify your tables column to be int(11) (or timestamp whichever).

 

Then when you insert a time into the db, you insert the actual time stamp.

 

$sql = "INSERT into tbl_name (`timest`) VALUES ('" . time() . "')";

 

That will insert it as a timestamp.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.