Page 1 of 1

How to add the time and date into MySql?

Posted: Sun Mar 15, 2009 9:58 am
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.

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

Posted: Sun Mar 15, 2009 11:44 am
by jh_1981
use php function date('Y-m-j H:i:s')

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

Posted: Sun Mar 15, 2009 12:35 pm
by MicroBoy
Can you tell me an example? Where I have to write it? In the form or where?

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

Posted: Sun Mar 15, 2009 12:38 pm
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)

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

Posted: Sun Mar 15, 2009 4:33 pm
by VladSun
Use MySQL function NOW()

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

Posted: Sun Mar 15, 2009 4:55 pm
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.

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

Posted: Sun Mar 15, 2009 5:17 pm
by VladSun

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

Posted: Mon Mar 16, 2009 12:50 pm
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...