date format

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
santille
Forum Newbie
Posts: 17
Joined: Thu Aug 05, 2004 1:31 pm

date format

Post by santille »

date format

Hello,

Code: Select all

for($m = 0;$m <= 0; $m++)
{
$now = date ("Y-m-d", mktime (0,0,0,date("m"),date("d")+$m,date("Y")));
echo "<input type=\"hidden\" name=\"open_date\" value=\"" . $now . "\">";
}
With this piece of code I want to get the following format with the hour and the minutes :
20-05-2009 10:00

Do you know how to modify?

Thanks,

seb
Last edited by Benjamin on Wed May 20, 2009 7:59 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: date format

Post by jaoudestudios »

$now = date ("Y-m-d", mktime (0,0,0,date("m"),date("d")+$m,date("Y")));
To...

Code: Select all

$now = date ("d-m-Y h:i", mktime (0,0,0,date("m"),date("d")+$m,date("Y")));
santille
Forum Newbie
Posts: 17
Joined: Thu Aug 05, 2004 1:31 pm

Re: date format

Post by santille »

I've tried but unsuccessfull!
The result with your code is : 0000-00-00
Another idea?

Thanks
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: date format

Post by onion2k »

If you used jaoudestudios you can't have 0000-00-00. You did something wrong.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: date format

Post by jaoudestudios »

for($m = 0;$m <= 0; $m++)
That is wrong! It wont run. Because $m will always be greater than 0.
santille
Forum Newbie
Posts: 17
Joined: Thu Aug 05, 2004 1:31 pm

Re: date format

Post by santille »

I've taken off this for loop but without success : always 0000-00-00 as the result..

Any idea?

Thanks,

seb
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: date format

Post by jaoudestudios »

Repost your current code
santille
Forum Newbie
Posts: 17
Joined: Thu Aug 05, 2004 1:31 pm

Re: date format

Post by santille »

Code: Select all

$now = date ("d-m-Y h:i", mktime (0,0,0,date("m"),date("d")+$m,date("Y")));
echo "<input type=\"hidden\" name=\"open_date\" value=\"" . $now . "\">";
Last edited by Benjamin on Wed May 20, 2009 7:59 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: date format

Post by jaoudestudios »

I ran...

Code: Select all

$now = date ("d-m-Y h:i", mktime (0,0,0,date("m"),date("d")+$m,date("Y")));
and get this...

Code: Select all

20-05-2009 12:00
NB: $m is undefined
santille
Forum Newbie
Posts: 17
Joined: Thu Aug 05, 2004 1:31 pm

Re: date format

Post by santille »

Here is the complete code of the page :

Code: Select all

 
<?
include 'header.php';
include 'format.css';
$queryu = "SELECT * FROM $userstable WHERE (userlevel = '2' OR userlevel = '3' OR userlevel = 'A') AND username = '$tmpname'";
$resultu = mysql_query($queryu); 
$rowu= mysql_fetch_array($resultu);
$userlevel = $rowu['userlevel'];
 
if($userlevel == '2'){
// DO NOTHING
echo "<table bgcolor=\"#ECECEC\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\" class=\"black\" border=\"0\">";
echo "<tr>";
echo "<td>You must have manager access to enter this area.</td>";
echo "</tr><table>";
}else{
//ELSE, SHOW FORM BELOW - Begin manager form
include 'includes/inputcheck.php';
echo "<td>";
 
echo "<table bgcolor=\"#ECECEC\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\" class=\"black\" border=\"0\">";
echo "<tr><td bgcolor=\"#ECECEC\" align=\"center\"><b>Task Creation</b></td><td bgcolor=\"#F2F2F2\" align=\"center\"><b>Customer Maintenance</b></td></tr>";
echo "<tr><td>";
 
echo "<table bgcolor=\"#ECECEC\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\" class=\"black\">";
echo "<tr><form name=\"form1\" method=\"post\" onSubmit=\"return (formCheck(this))\" action=\"complete.php?getid=1\">";
echo "<td align=\"right\"><b>Customer:</b></td> ";
echo "<td><select name=\"catname\">";
echo "<option value=\"\"></option>";
include 'includes/catecon.php';
echo "</select></td></tr>";
/*for($m = 0;$m <= 0; $m++){
    $now = date("Y-m-d h:i", strtotime("now + $m day"));
    echo "<input type='hidden' name='open_date' value='$now' />\n";
}*/
for($m = 0;$m <= 0; $m++)
{
$now = date ("Y-m-d", mktime (0,0,0,date("m"),date("d")+$m,date("Y")));
echo "<input type=\"hidden\" name=\"open_date\" value=\"" . $now . "\">";
}
/*echo "<tr><td align=\"right\"><b>Priority:</b></td><td><select name=\"priority\">";
echo "<option value=\"\"></option>";
include 'includes/priorcon.php';
echo "</select> <font size=\"1\">Lower numbers are higher priority</font></td></tr>";*/
echo "<tr><td align=\"right\"><b>Customer Site:</b><td><input type=\"text\" name=\"site\" value=\"\" size=\"25\"><br></td></tr>";
echo "<tr><td align=\"right\"><b>Modem #:</b><td><input type=\"text\" name=\"modem\" value=\"\" size=\"25\"><br></td></tr>";
echo "<tr><td align=\"right\"><b>Task Name:</b><td><input type=\"text\" name=\"title\" value=\"\" size=\"25\"><br></td></tr>";
echo "<tr><td align=\"right\"><b>Description:</b><td><textarea name=\"description\" cols=\"25\" rows=\"5\"></textarea><br></td></tr>";
echo "<tr><td align=\"right\"><b>Assignee:</b></td><td><select name=\"personnel\">";
echo "<option value=\"\"></option>";
include 'includes/personnel.php';
echo "</select></td></tr>";
echo "<tr><td align=\"right\"><b>Caller's Name:</b><td><input type=\"text\" name=\"caller\" value=\"\" size=\"25\"><br></td></tr>";
echo "<tr><td align=\"right\"><input type=\"submit\" value=\"Submit Task\"></td></tr>";
echo "<tr><td align=\"center\" colspan=\"2\">";
echo "</form></td></tr></table>";
echo "</td>";
 
echo "<td bgcolor=\"#F2F2F2\" valign=\"top\"><br>";
echo "<table width=\"70%\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\" class=\"black\" border=\"0\">";
$sql = "SELECT * FROM $taskstable WHERE taskid = '$taskid' GROUP BY open_date";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
echo "<form name=\"form2\" method=\"post\" onSubmit=\"return (formCheck(this))\" action=\"complete.php?getid=112\">";
echo "<tr><td align=\"right\" colspan=\"2\"><b>Add:</b> <input type=\"text\" name=\"catname\" value=\"\" size=\"20\"> <input type=\"submit\" value=\"Add Customer\"></td></tr></form>";
 
echo "<form name=\"form2\" method=\"post\" action=\"complete.php?getid=56\"><tr><td align=\"right\" colspan=\"2\"><br> <b>Delete:</b> 
<select name=\"catnamedel\"><option value=\"\"></option>";
include 'includes/catecon.php';
echo "</select> <input type=\"submit\" value=\"Delete Customer\"></td>";
echo "</tr></form>";
echo "</table>";
 
echo "</td>";
echo "</tr><table>";
 
echo "<br><br></td>";
echo "</tr>";
echo "</table>";
}
/*include 'footer.php';*/
 
?>
 
Last edited by Benjamin on Wed May 20, 2009 8:00 am, edited 1 time in total.
Reason: Changed code type from text to php.
rugbyfreak
Forum Newbie
Posts: 10
Joined: Sat May 16, 2009 12:41 pm

Re: date format

Post by rugbyfreak »

Code: Select all

date_default_timezone_set('Europe/Brussels');
$date=date(" d - m - y  g:m:s");
echo $date;
$sql="INSERT INTO commentaire (commentaire, datetime) 
VALUES
('$_POST[commentaire]','$_POST[date]')";
 
1) the 'commentaire' is always posted but not the date.
2) do i have to echo the date to post it?
Last edited by rugbyfreak on Thu May 21, 2009 9:06 am, edited 2 times in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: date format

Post by Benjamin »

rugbyfreak - use

Code: Select all

when posting code.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: date format

Post by jaoudestudios »

rugbyfreak wrote:2) do i have to echo the date to post it?
No, remove the quotes!
Post Reply