Jump to content

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

If you read it carefully, you'd know it's the best way to store it.

 

You just need to know some extra functions, to convert dates stored in mysql format to your desired format.

These are

strtotime and date in PHP

There are also their analogues in MySQL

 

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.

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

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.

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.