SQL Timestamp

PythonPython Forum LeaderThe Royal RAM
Ive got this script that adds some stuff into a database and when it does this one of the fields is set to TIMSTAMP so that it will put in the current time...

But i dont understand how to then use it. Because timestamp is just a bunch of numbers, 8 i think. How do I put that into the real time format. eg:

HH:MM:SS DD:MM:YY

thanks

The Royal Ram

Comments

  • pavstapavsta Beginner Link Clerk
    I can help you here, basically if i remember rightly you need to convert the timestamp data, first fetch the info from the database, ill call the field with the timestamp 'time' and the variable that fetch's it ill call $grab, now this is the code you need:

    $date = date("d/m/Y G:i:s","$grab[time]");

    and so when the $date variable is called it will display something like: 20/1/2005 23:54:05

    - Hoped this helped.
  • PythonPython Forum Leader The Royal RAM
    ahh rite i see... so you actually define th order in which it is all outputted. Ok thanks :)

    The Royal Ram

  • pavstapavsta Beginner Link Clerk
    yep, thats the best thing! :)
  • ArestiaArestia Member NAT Warrior
    i use this to format timestamps, timestamp(14) that is
    <?php
    function format_timestamp($timestamp)
    {
    	$year = substr($timestamp, 0, 4);
    	$month = substr($timestamp, 4, 2);
    	$day = substr($timestamp, 6, 2);
    	$hour = substr($timestamp, 8, 2);
    	$minute = substr($timestamp, 10, 2);
    	$second = substr($timestamp, 12, 2);
    	if($hour >= 12)
    	{
    		if($hour > 12)
    		{ $hour = $hour - 12; }
    		$ampm = "PM";
    	}
    	else
    	{
    		$hour = $hour - 0;
    		$ampm = "AM";
    	}
    	$formatted = $year.".".$month.".".$day." - ".$hour.":".$minute." ".$ampm;
    	return $formatted;
    }
    ?>
    

    then you can call it using
    format_timestamp($myrow[yourtimestamp])
    

    and this the style it displays "2005.01.25 - 9:05 PM".

    you can format the $formated variable to your liking.

    -Dan
    Arestia Design Studios / Synapse Corporate Solutions
    Daniel L. Rust - Lead Architect
    Seattle, WA
  • PythonPython Forum Leader The Royal RAM
    well thats a lot more code but yeah that seems fairly good :)

    The Royal Ram

Sign In or Register to comment.