SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Member
    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']}\" />";
    
    ?>

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    There's nothing in the code that would change the way it displays. You need to find where the timestamp is echoed.

  3. #3
    SitePoint Addict
    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?
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?

  4. #4
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    There's nothing in the code that would change the way it displays. You need to find where the timestamp is echoed.
    Quote Originally Posted by alex.w747 View Post
    Usually the date function is used to format date and time in PHP.

    So maybe you can find a place where the date is printed and check how it is printed?

    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>
    This doesn't look like it..
    Both of these are from index.php

    Code:
    //****CALCULATE THE OFFSET TIME************************************************************
    
    	$OFFSETTIME = date("Y-m-d H:i:s", time() + ($TIMEOFFSET * 60 * 60));
    	
    //***************************************************************************************
    Maybe this?

    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.

  5. #5
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.

  6. #6
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    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.
    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.

  7. #7
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    '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?

  8. #8
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    '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?
    Its not just one file.. It's an entire cms. go here>> www,supersimple,org ( << commas instead of periods )

  9. #9
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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));
        
    //*************************************************************************************** 
    You could change that and have the current date formatted as you want, as well as enter the dates manually in the new format henceforth. And also change any existing dates in the db to the new format.

    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.

  10. #10
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View 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));
        
    //*************************************************************************************** 
    So what would I enter to change the date and month's places?
    Also, you said something about changing something in the DB.. I took a look and didn't see much to change?

    Thanks for all the help so far.

  11. #11
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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)); 

  12. #12
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "d/m/Y" = Nothing shows
    "Ymd" = Date shows as before eg.. March 06 2009 >> 12:00 << The time is incorrect tho
    "Y-m-d H:i:s" = Shows as before.. with time working. Go figure.

    Does this kind of give you a clue as to what is happening?

    Quote Originally Posted by php_daemon View Post
    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)); 

  13. #13
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.

  14. #14
    SitePoint Member
    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 ";
    
    }
    Works like a charm. Thanks so much for your help.. I did learn something, not sure what.. (scour code next time)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •