Page 1 of 1

[SOLVED] date & Time Conversion

Posted: Fri Sep 29, 2006 7:16 am
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

Posted: Fri Sep 29, 2006 7:28 am
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!

Re: date & Time Conversion

Posted: Fri Sep 29, 2006 7:32 am
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

Posted: Fri Sep 29, 2006 8:14 am
by printf
Sorry about that....

// mssql

Code: Select all

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

me!

Posted: Sun Oct 01, 2006 8:34 pm
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

Posted: Mon Oct 02, 2006 1:11 am
by ryuuka
printf wrote:

Code: Select all

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

thanks this works