Jump to content

Recommended Posts

I am trying to get the date to show on my page in a particular way.

 

I have a database Table called 'actions' set up like this;

Field------------ Type------- Collation-------Attributes------Null--- Default

date------------ timestamp------------------------------------------No-----CURRENT_TIMESTAMP

 

My code that requests the time is;

$date = time();

 

I insert it in to the database like this;

$queryreg = mysql_query("INSERT INTO " . TBL_ACTION . "  ( `date`) VALUES ('$date')");

 

 

I call the date to the page like this

<?php echo $data['date']; ?>

 

But this shows the date on my page like this

 

Thu 1st January 1970 12.00AM

 

What am I doing wrong?> I want it in this format but with the current data and time

 

 

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/189100-date-issues/
Share on other sites

The default is 'CURRENT_TIMESTAMP' so you don't need to pass a value,

but if you want to pass it, you need to format it to MySQL time

 

$date = date('Y-m-d H:i:s',time());

 

OR for default

$queryreg = mysql_query("INSERT INTO " . TBL_ACTION . "  ( `date`) VALUES (null)")

Link to comment
https://forums.phpfreaks.com/topic/189100-date-issues/#findComment-998360
Share on other sites

Also, as MadTechie mentioned you don't need to specify the date since it's automatic, however in the situation when it isn't, you can use the mysql NOW() function instead of specifying the date from a php variable.

 

Check out php.net info on date() for more info on format strings.

 

http://us3.php.net/manual/en/function.date.php

Link to comment
https://forums.phpfreaks.com/topic/189100-date-issues/#findComment-998361
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.