Timestamp help!

[php]<?php
include “logo.php”;

echo "The Maske Weblog

";

include “welcome.php”;

$query = “SELECT id,title,text,date,posted,submitted FROM weblog WHERE posted != ‘0’ ORDER BY date DESC, id DESC LIMIT 0,8”;
$exec = mysql_query($query);

while ($result = mysql_fetch_array($exec)) {
$id = $result[“id”];
$title = htmlspecialchars($result[“title”]);
$text = ubb_advanced(ubb_basic(nl2br(htmlspecialchars($result[“text”]))));
$time = get_date_short($result[“date”]);
$posted = $result[“posted”];
$submitted = $result[“submitted”];

$posted_name = get_name($posted);

if ($submitted > ‘0’) {
$submitted_name = get_name($submitted);
$submitted = " submitted by $submitted_name";
}

else {
$submitted = “”;
}

$reaction_exec = mysql_query(“SELECT weblog FROM weblog_reactions WHERE weblog=’$id’”);
$reaction_check = mysql_num_rows($reaction_exec);

if ($reaction_check == ‘0’) {
$reaction = "

:open: - :no reactions: - ";
}

elseif ($reaction_check == ‘1’) {
$reaction = "

:open: - :1 reaction: - ";
}

else {
$reaction = "

:open: - :$reaction_check reactions: - ";
}

$reaction = $reaction . “:add reaction:”;

echo "

$title
Posted by: $posted_name</b$submitted on $date at $time
$text

$reaction
"; }

echo “

”;
?>[/php]

That was my code, i was wondering, i know where every thing apears but i want the outcome to be that it says in my weblog:

Posted by ‘user’ on ‘day thehowmanieth of month’ at ‘24hour time’. I don’t exactly where to configure it on this one. Thank you.

The HTML for the line:

Posted by: <a href='index.php?user=pm&action=send&to=$posted'><b>$posted_name</b</a>$submitted on <b>$date</b> at <b>$time</b>

$date is the date variable (I assume)
and
$time is the time variable (again I assume)

Where are the variables coming from:

$query = "SELECT id,title,text,date,posted,submitted FROM weblog WHERE posted != '0' ORDER BY date DESC, id  DESC LIMIT 0,8";
$exec = mysql_query($query);
while ($result = mysql_fetch_array($exec)) {
....  
$time = get_date_short($result["date"]);
....
} 

I don’t see where you generate the date variable in your code. Maybe it is
in the get_date_short function (user defined function). That is where we need to look I think for your answers.

Look at that user function and you will probably see the PHP date() and/or time() function. Check out the manual to see how to modify them for your needs.

Yeh I’m sorry, i forgot to include this, this is from my file functions.php holding in all the commands, i recently edited it so it has a list of all days but it still won’t work. Plus, in the first set of code showing get_date_short i changed to get_date_archive:

[php]<?php
function get_date_short($date) {
$today = @gmdate(‘Ymd’, time() + (3600 * 2));
$compare = substr($date ,0,8);

$day = substr($date, 6,2);
$month = substr($date, 4,2);
$hours = substr($date, 8,2);
$minutes = substr($date, 10,2);

if ($today == $compare) {
return “$hours:$minutes”;
}

else {
return “$day/$month”;
}
}

function get_date_long($date) {
$day = substr($date, 6,2);
$month = substr($date, 4,2);
$year = substr($date, 0,4);

return “$day-$month-$year”;
}

function get_date_archive($date) {
$day = substr($date, 6,2);
$month = substr($date, 4,2);
$year = substr($date, 0,4);

$day_array = array(“Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”);
$day = $day_array[$day - 1];

$month_array = array(“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”);
$month_text = $month_array[$month - 1];

return “$day $month_text $year”;
}

function get_name($id) {
$exec = mysql_query(“SELECT name FROM users WHERE id=’$id’”);
$result = mysql_fetch_array($exec);
$name = $result[“name”];

return “$name”;
}

function get_id($name) {
$exec = mysql_query(“SELECT id FROM users WHERE name=’$name’”);
$result = mysql_fetch_array($exec);
$id = $result[“id”];

return “$id”;
}

function ubb_basic($text) {
$text = preg_replace("/()(.*)()/siU", “\4”,$text);

$text = eregi_replace("[center]","",$text);
$text = eregi_replace("[/center]","",$text);
$text = eregi_replace("","",$text);
$text = eregi_replace("
","",$text);
$text = eregi_replace("","",$text);
$text = eregi_replace("
","",$text);
$text = eregi_replace("","",$text);
$text = eregi_replace("
","",$text);

return ($text);
}

function ubb_advanced($text) {
$text = preg_replace("/img[/img]/is", ‘’, “$text”);
$text = preg_replace("/img w=(.+?) h=(.+?)[/img]/is", ‘’, “$text”);

return ($text);
}
?>[/php]

The date function in the manual allows you to load in the date you want to be converted as a timestamp (date taken out of the DB - is it a timestamp or a string?)

what is going wrong with your array fix? or you can take the numbers you are getting and do a switch to get the english name for what you want.

[php]<?php
include “logo.php”;

echo "The Maske Weblog

";

include “welcome.php”;

$query = “SELECT id,title,text,date,posted,submitted FROM weblog WHERE posted != ‘0’ ORDER BY date DESC, id DESC LIMIT 0,8”;
$exec = mysql_query($query);

while ($result = mysql_fetch_array($exec)) {
$id = $result[“id”];
$title = htmlspecialchars($result[“title”]);
$text = ubb_advanced(ubb_basic(nl2br(htmlspecialchars($result[“text”]))));
$date = get_date_archive($result[“date”]);
$posted = $result[“posted”];
$submitted = $result[“submitted”];

$posted_name = get_name($posted);

if ($submitted > ‘0’) {
$submitted_name = get_name($submitted);
$submitted = " submitted by: $submitted_name";
}

else {
$submitted = “”;
}

$reaction_exec = mysql_query(“SELECT weblog FROM weblog_reactions WHERE weblog=’$id’”);
$reaction_check = mysql_num_rows($reaction_exec);

if ($reaction_check == ‘0’) {
$reaction = "

:open: - :no reactions: - ";
}

elseif ($reaction_check == ‘1’) {
$reaction = "

:open: - :1 reaction: - ";
}

else {
$reaction = "

:open: - :$reaction_check reactions: - ";
}

$reaction = $reaction . “:add reaction:”;

echo "

$title
Posted by: $posted_name</b$submitted
Post date: $date
$text

$reaction
"; }

echo “

”;
?>[/php]

Sorry for my trouble, the first post in this thread was outdated and didn’t make any sense, referring to the ‘functions.php’ this is the new code.

Sponsor our Newsletter | Privacy Policy | Terms of Service