How to add the time and date into MySql?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MicroBoy
Forum Contributor
Posts: 112
Joined: Sat Mar 14, 2009 5:16 pm

How to add the time and date into MySql?

Post by MicroBoy »

I add some informations in the MySql with a form (Like: Name, Last Name, Age etc...), and I want to add the Current Time&Date into database, so I don't want to write the current time&date by myself.
jh_1981
Forum Newbie
Posts: 22
Joined: Fri Jan 30, 2009 6:21 pm

Re: How to add the time and date into MySql?

Post by jh_1981 »

use php function date('Y-m-j H:i:s')
MicroBoy
Forum Contributor
Posts: 112
Joined: Sat Mar 14, 2009 5:16 pm

Re: How to add the time and date into MySql?

Post by MicroBoy »

Can you tell me an example? Where I have to write it? In the form or where?
jcrensha627
Forum Newbie
Posts: 15
Joined: Fri Feb 27, 2009 11:34 pm

Re: How to add the time and date into MySql?

Post by jcrensha627 »

micro, im pretty new myself but i believe you do it from the backend. are u using phpmyadmin?? if so create another column named time and change the type to datetime or whatever other option want. if your not using myadmin im not to sure. hope this helped 8)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: How to add the time and date into MySql?

Post by VladSun »

Use MySQL function NOW()
There are 10 types of people in this world, those who understand binary and those who don't
MicroBoy
Forum Contributor
Posts: 112
Joined: Sat Mar 14, 2009 5:16 pm

Re: How to add the time and date into MySql?

Post by MicroBoy »

I'm to confuse, here is my code where to put or what to do, yes I'm using phpmyadmin:

Code: Select all

 
<html>
<body>
<?php
include ("menu/menu.php");
if (empty($_POST['dergo']))
{
?>
<TABLE class="col_top" width="800" align="left" cellspacing="0" cellpadding="0" border="0">
  <TR>
<TD valign="left">
</br>
<strong><center><form action="<?=$_SERVER['PHP_SELF']?>" method="post">
Emri: <input type="text" name="emri" /></br>
Lajmi: <textarea name="lajmi" rows="5" cols="26"></textarea></br>
Data: <input type="data" name="data" /></br>
<input type="submit" name="dergo" value="Dërgo" />
</form></center></strong>
 
<?php
}
if (isset($_POST['dergo'])) {
 
include ('konfig.php');
 
$con = mysql_connect("$serveri","$username","$fjalekalimi");
if (!$con)
  {
  die('Nuk Mund Të Konektohet: ' . mysql_error());
  }
 
mysql_select_db("$databaza", $con);
 
$sql="INSERT INTO lajmet (emri, lajmi, data)
VALUES ('$_POST[emri]','$_POST[lajmi]','$_POST[data]')";
 
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "</br><center><strong>Lajmi U Shtua Me Sukses Nga: $_POST[emri] <strong></br></center>";
echo '<center><a href="http://localhost/elektro/shto.php">Kthehu</a> Prapa Për Të Shtuar Lajm Të Ri</center>';
 
mysql_close($con);
}
?>
<?php
include ('posht.php');
?>
 </TR>
</TABLE>
</body>
</html>
 
p.s. If you don't understand anything just ask, cause some variables etc... are in Albanian.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: How to add the time and date into MySql?

Post by VladSun »

There are 10 types of people in this world, those who understand binary and those who don't
MicroBoy
Forum Contributor
Posts: 112
Joined: Sat Mar 14, 2009 5:16 pm

Re: How to add the time and date into MySql?

Post by MicroBoy »

Everything is fine now with it, I'm using as a variable $time= date("l d F Y, H:i:s"); But now I would like the days and months to be in my language, Is any way to change the name of the days and months like, Monday, Tuesday, January etc...
Post Reply