date time insertion using php mysql

someone please help me out!! help appreciated

Page 1 of 1

8 Replies - 11752 Views - Last Post: 27 February 2010 - 09:34 AM Rate Topic: -----

#1 phpnoob  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 29
  • Joined: 22-August 09

date time insertion using php mysql

Posted 26 February 2010 - 05:35 AM

hello everyone!!

problem statement--> I want to insert date and time in mysql database using php

and want to display the time date and year in the post.


I already created date column in database

where i kept data type as date and time


here is my code


html submisssion form

<html>
<body>
<form action="pdt.php" method="post">
<input type="text" name="name">
<input type="submit" value="submit">
</form>
</body>
</html>



--------------php process script----------------
<?php
include('connect.php');
$mysqldate = date( 'Y-m-d H:i:s', $phpdate );
$phpdate = strtotime( $mysqldate );
$name=$_POST['name'];

$query = "UPDATE datetime SET date= FROM_UNIXTIME($phpdate)";
$exe=mysql_query($query);
if($exe==1)
{
echo "sucess";
}
else{
echo mysql_error();
}

?>




thank you in advance

This post has been edited by JackOfAllTrades: 26 February 2010 - 07:34 AM
Reason for edit:: Added code tags. PLEASE!!! [code]...PUT YOUR CODE IN HERE...[/code]


Is This A Good Question/Topic? 0
  • +

Replies To: date time insertion using php mysql

#2 phpnoob  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 29
  • Joined: 22-August 09

Re: date time insertion using php mysql

Posted 26 February 2010 - 05:47 AM

hi everyone its little bit urgent

I need to implement into my social networking site!!


thank you in advance
Was This Post Helpful? 0
  • +
  • -

#3 phpnoob  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 29
  • Joined: 22-August 09

Re: date time insertion using php mysql

Posted 26 February 2010 - 06:04 AM

still waiting :P
Was This Post Helpful? 0
  • +
  • -

#4 Xuhybrid  Icon User is offline

  • D.I.C Head

Reputation: 30
  • View blog
  • Posts: 106
  • Joined: 20-January 10

Re: date time insertion using php mysql

Posted 26 February 2010 - 07:06 AM

You would need something more like this:

<?php

include('connect.php');

$name = $_POST['name'];
$sql = "INSERT INTO `posts` (`name`, `time`) VALUES ('".$name."', '".time()."')";
$exe = mysql_query($sql);

if ($exe)
{
	echo "success";
}
else
{
	echo mysql_error();
}

?>

This is where you have a table called posts with the columns name and time.

When you output this data into HTML, use this:

<?php
	$time = //time from database
	echo date("d/m/y H:i", $time);
?>

See http://php.net/manua...nction.date.php for date formatting options.

This post has been edited by Xuhybrid: 26 February 2010 - 07:10 AM

Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: date time insertion using php mysql

Posted 26 February 2010 - 07:34 AM

Do NOT bump a topic after a mere 10 minutes...we aren't here to serve you.
Was This Post Helpful? 1
  • +
  • -

#6 phpnoob  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 29
  • Joined: 22-August 09

Re: date time insertion using php mysql

Posted 27 February 2010 - 03:13 AM

hello bro its giving some arbit value!

when i set the table data type as varchar its giving the value 1267265044

if i set it to timestamp its giving the value 0000-00-00 00:00:00


i have script that runs but its not matching my system time

i want to display the date in this format

for example

28 feb 2010 10pm

how would i do that

please figure it out, if you got time

thank you

this is my code


include('connect.php');
$date=date("d M h:i A", time());
$name=$_POST['name'];
$query="insert into datetime values('$name',NOW())";
$exe=mysql_query($query);
if($exe==1)
{
$check="select * from datetime";
$echeck=mysql_query($check);
while($result=mysql_fetch_array($echeck))
{

output----of this code is

2010-02-27 00:24:48

i don't want in this format


how can i change the format of display and make it look like

for example

28 feb 2010 8pm
  $result['date'];

}
}


this is my code


include('connect.php');
$date=date("d M h:i A", time());
$name=$_POST['name'];
$query="insert into datetime values('$name',NOW())";
$exe=mysql_query($query);
if($exe==1)
{
$check="select * from datetime";
$echeck=mysql_query($check);
while($result=mysql_fetch_array($echeck))
{

output----of this code is

2010-02-27 00:24:48

i don't want in this format


how can i change the format of display and make it look like

for example

28 feb 2010 8pm
  $result['date'];

}
}

Was This Post Helpful? 0
  • +
  • -

#7 phpnoob  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 29
  • Joined: 22-August 09

Re: date time insertion using php mysql

Posted 27 February 2010 - 08:21 AM

there is no one in this forum who could solve this problem
Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: date time insertion using php mysql

Posted 27 February 2010 - 08:34 AM

Look through the freaking manual to find a function that will format the data the way you like. If you'd rather do it in PHP, then THEY have a freaking manual too!
Was This Post Helpful? 0
  • +
  • -

#9 hadi_php  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 10
  • View blog
  • Posts: 382
  • Joined: 23-August 08

Re: date time insertion using php mysql

Posted 27 February 2010 - 09:34 AM

i think you should create a filed in table

like - create_time as TIMESTAMP format...

Then no need to mention the time in code. when you will insert data in other field and keep that create_time field empty .... when insertion will complete then current date time will added automatically....
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1