[SOLVED] date & Time Conversion

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
ryuuka
Forum Contributor
Posts: 128
Joined: Tue Sep 05, 2006 8:18 am
Location: the netherlands

[SOLVED] date & Time Conversion

Post by ryuuka »

hello again

this time i have another problem concerning the time notation:

my database ouputs the date in a different type than the one my code needs

the date that i get now is like this:

28-8-2006 16:36:00

and the one that i want is:

2006-08-28 16:36

what would be the best way to change this?
this is my code the date is being put out in the variables:

Code: Select all

$Latestcheck
$Firstcheck

Code: Select all

<?php
  $rs = $objConn->Execute("SELECT TOP 1 LastCheck as Latestcheck, ServerName, Status
                              FROM Ryuuka_ServerPingStatus
                              WHERE (ServerName = 'sr0001')
                              ORDER BY Latestcheck DESC");
  $rsa = $objConn->Execute("SELECT TOP 1 LastCheck as Firstcheck, ServerName, Status
                              FROM ryuuka_ServerPingStatus
                              WHERE (ServerName = 'sr0001')
                              ORDER BY Firstcheck ASC");


  while (!$rs->EOF) {
    $ServerName            = $rs->fields['ServerName' ]->value;
    $Status                     = $rs->fields['Status'     ]->value;
    $Latestcheck            = $rs->fields['Latestcheck'  ]->value;

    $rs->MoveNext();
    }

    while   (!$rsa->EOF){
    
    $Firstcheck            = $rsa->fields['Firstcheck'  ]->value;

   // settype($Firstcheck,       "string");

    $rsa->MoveNext();
    }

?>
oh and if you say something like use strtime() please include a code example
i've never used that class before
Last edited by ryuuka on Mon Oct 02, 2006 1:13 am, edited 1 time in total.
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post by printf »

Do it in your query...

Code: Select all

SELECT ... DATE_FORMAT(date_column, '%Y-%m-%d %H:%i') AS formatted_date ...

Where...

date_column = the column that holds the data and time
formatted_date = the resulting key name returned from the query -> $row['formatted_date'] or $rs->fields['formatted_date']->value;


me!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: date & Time Conversion

Post by volka »

ryuuka wrote:$rs = $objConn->Execute("SELECT TOP 1 LastCheck as Latestcheck, ServerName, Status
I suggest you always add "I use MSSQL" to your questions ;)

Take a look at http://www.databasejournal.com/features ... hp/2197931
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post by printf »

Sorry about that....

// mssql

Code: Select all

SELECT ... CONVERT(VARCHAR(16), date_column, 120) AS formatted_date

me!
chakhar86
Forum Commoner
Posts: 45
Joined: Mon Jun 05, 2006 1:36 am
Contact:

Post by chakhar86 »

Have you tried strtotime() function?
It will convert your date/time to integer value, then you just simply use date() function to arrange the output to meet your requirement
ryuuka
Forum Contributor
Posts: 128
Joined: Tue Sep 05, 2006 8:18 am
Location: the netherlands

Post by ryuuka »

printf wrote:

Code: Select all

SELECT ... CONVERT(VARCHAR(16), date_column, 120) AS formatted_date

thanks this works
Post Reply