SitePoint Sponsor |
|
User Tag List
Results 1 to 14 of 14
Thread: TIMESTAMP - Change time format?
-
Mar 5, 2009, 07:48 #1
- Join Date
- Mar 2009
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
TIMESTAMP - Change time format?
Hello all!
This is my first PHP project, and I would appreciate your help.
Ok, I really don't know what I'm doing but here is some of the code, I'll try to explain my problem as clearly as possible.. (it's mostly greek to me)
I'm using the Awesome Super Simple Blog Script.... The problem is: it doesn't give the ability to change the way Time is formatted! Orig: March 6, 2009 5:09 pm --- What I want: 06/03/2009 (and don't want the time).
The way I understand how this particular code works is. The PHP requests the server time then displays the time requested in each post.. I think.
The code I'll post is from the edit.php files included in the "Super Simple Blog Script"
Here is the code... I think it pertains to time.
Code://we will build the query without updating the KEY $names[] = $key; $values[] = $value; //blobs are long, so we need to display in a textarea if($dataTypes[$i] == 'blob'){ echo "\n<tr>\n<td>$key:<br /><textarea name=\"$dataNames[$i]\" >$value</textarea></td>\n</tr>\n"; //the other datatypes are generally shorter, so we can use an input } else if($dataTypes[$i] == 'string' || $dataTypes[$i] == 'int' || $dataTypes[$i] == 'real' || $dataTypes[$i] == 'timestamp' || $dataTypes[$i] == 'year' || $dataTypes[$i] == 'date' || $dataTypes[$i] == 'time' || $dataTypes[$i] == 'datetime'){ echo "\n<tr>\n<td>$key:"; //give some format hints for timestamp if($dataTypes[$i] == 'timestamp'){echo " YYYY MM DD HH MM SS <em>or</em> <input type=\"checkbox\" name=\"$dataNames[$i]NOW\" style=\"width:10px; height:10px;\" />Set to current time";} echo"<br /><input type=\"text\" value=\"$value\" name=\"$dataNames[$i]\" /></td>\n</tr>\n"; } }else{ //this is our PRIMARY KEY echo "\n<input type=\"hidden\" value=\"$value\" name=\"$dataNames[$i]\" />\n"; } $i++; }//end foreach }//end while //we use hidden fields for passing table information echo "<input type=\"hidden\" name=\"tableName\" value=\"{$_GET['table']}\" />"; echo "<input type=\"hidden\" name=\"colName\" value=\"{$_GET['colName']}\" />"; echo "<input type=\"hidden\" name=\"colVal\" value=\"{$_GET['colVal']}\" />"; ?>
-
Mar 5, 2009, 07:58 #2
There's nothing in the code that would change the way it displays. You need to find where the timestamp is echoed.
-
Mar 5, 2009, 07:58 #3
- Join Date
- Dec 2007
- Posts
- 358
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Usually the date function is used to format date and time in PHP.
http://php.net/date
So maybe you can find a place where the date is printed and check how it is printed?
-
Mar 5, 2009, 08:06 #4
- Join Date
- Mar 2009
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Could this be it?
This is from edit.php
Code:<style type="text/css" media="all">@import "../blogStyles.css";</style> <body> <form enctype="multipart/form-data" action="<?='../'.$blogPageName; ?>" method="post" name="add"> <input type="hidden" name="MAX_FILE_SIZE" value="5000000"> <!--sets the max file size that this form will handle. php.ini file has more control than this.--> <input type="hidden" name="uid" value="<?=$_this_uid ?>" /> <input type="hidden" name="col" value="<?=$_this_col ?>" /> <input type="hidden" name="table_name" value="<?=$_this_table_name ?>" /> <input type="hidden" name="origtime" value="<?=$_this_time ?>" /> <div><p><b>Time: </b><br /><input type="checkbox" name="time" /> Change to current time</p></div> <div id="title"> <p><b>Title: </b><br /><input type="text" name="title" style="width:340px;" value="<?=$_this_title ?>" /><br /></p> </div> <div id="content"> <p><b>Comment: </b> <? if($imagesPerEntry > 1){echo "<br /><em>Insert \"[#]\" in place of each image that you want to display (eg. lorem ipsum [1] sic dol amet...)</em>";} ?> <br /><textarea name="comment" style="width:340px;height:250px"><?=$_this_comment ?></textarea><br /> </div> <div id="image"> <?php #create the file uploads for($i=0; $i < $imagesPerEntry; $i++){ $j = $i + 1; echo "<p>Add Image: [$j] <span class=\"accent\">| current file: $_this_image[$i]</span><br /><input type=\"file\" name=\"upload$i\" value=\"$_this_image[$i]\"/></p>"; echo "<input type=\"hidden\" name=\"image$i\" value=\"$_this_image[$i]\" />\n"; } ?> </div>
Both of these are from index.php
Code://****CALCULATE THE OFFSET TIME************************************************************ $OFFSETTIME = date("Y-m-d H:i:s", time() + ($TIMEOFFSET * 60 * 60)); //***************************************************************************************
Code://check to see if the entry time will be updated to current time, or remain the original time if($_POST['time']){ $time = $OFFSETTIME; }else{ $time = $_POST['origtime']; } $t = escape_data($_POST['title']); $c = escape_data($_POST['comment']); $un = escape_data($_POST['username']);
Last edited by copudesign; Mar 5, 2009 at 09:10.
-
Mar 5, 2009, 09:28 #5
You shouldn't be looking in the editting, adding or saving parts of the code, but displaying it. You don't know how and where those dates are used, if you change the way they are stored in the db, you may need to make adjustments all throughout the script wherever timestamp is used.
Look in the templates (if there's such thing in this script), or anywhere you see the data taken out of the db and displayed on the page.
-
Mar 5, 2009, 10:15 #6
- Join Date
- Mar 2009
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok, what type of string of code should I be looking for?
KK, I found something..
Code://****INSERT INTO DB*********************************************************************** if($_db_operation == 'insert'){ //Add the record to the database. $query = "INSERT INTO $TABLENAME (comment, title, image, time, postedBy) VALUES ('$c', '$t', '$filename', '$OFFSETTIME', '$un' )"; $result = @mysql_query($query); echo '<h1>Comment added</h1>'; } else if($_db_operation == 'update'){ //Update the record to the database. $query = "UPDATE $TABLENAME SET comment = '$c' , title = '$t', image = '$filename', time = '$time', postedBy = '$un' WHERE $editCol = '$uid'"; $result = @mysql_query ($query); echo '<h1>Comment added</h1>'; }
Last edited by copudesign; Mar 5, 2009 at 10:49.
-
Mar 5, 2009, 11:13 #7
'echo $time' or something along the lines.
That's inserting and updating again.
What is the filename of the script that shows your posts which have the date that you want to be in the new format?
-
Mar 5, 2009, 11:16 #8
- Join Date
- Mar 2009
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Mar 5, 2009, 11:41 #9
I don't see any dates there...
I assumed you want that date to be displayed on your site, is it not the case?
From what I gather from the snippets, the timestamp is either specified by hand when you enter the post or the current time is taken and formatted here:
PHP Code://****CALCULATE THE OFFSET TIME************************************************************
$OFFSETTIME = date("Y-m-d H:i:s", time() + ($TIMEOFFSET * 60 * 60));
//***************************************************************************************
Just as a note. It isn't the best way of doing this, the consistency is not very fool proof. Should you make a mistake by entering a date manually, it would be saved as is. As well as you lose data with the new format as it does not include time - only date. Ideally, it should be saved in a uniform format in db and only formatted when displayed.
-
Mar 5, 2009, 12:01 #10
- Join Date
- Mar 2009
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Mar 5, 2009, 12:44 #11
By saying that I mean you need to edit the posts in the cms and change their dates. In fact, that should work without any code changes if it works as I think it does.
The format you want is:
PHP Code:$OFFSETTIME = date("d/m/Y", time() + ($TIMEOFFSET * 60 * 60));
-
Mar 5, 2009, 13:36 #12
- Join Date
- Mar 2009
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Mar 5, 2009, 14:21 #13
I think the date is broken apart and then formatted before displaying, so you can't do that what you just did. That brings us to my original point - you need to find where it is displayed.
-
Mar 5, 2009, 14:27 #14
- Join Date
- Mar 2009
- Posts
- 7
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I don't know how I didn't see this:
Code:$_perma_entry = cleanEntry($_GET['entry']); $query = "SELECT comment, image, title, DATE_FORMAT(time, '%d/%m/%Y %h:%i%p') AS time, uid, comments, postedBy, time AS ts FROM $TABLENAME WHERE uid = '$_perma_entry' LIMIT 1"; }else{ $query = "SELECT comment, image, title, DATE_FORMAT(time, '%d/%m/%Y %h:%i%p') AS time, uid, comments, postedBy, time AS ts FROM $TABLENAME ORDER BY ts DESC LIMIT $bPage,$perPage "; }
Thanks so much for your help.. I did learn something, not sure what.. (scour code next time)
Bookmarks