Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert datetime to show just date 1

Status
Not open for further replies.
Jan 28, 2003
18
US
I am new to PHP, trying to learn on my own but I am having an issue. I am querying my mssql db and showing the return data to a table on a page, but I am having trouble converting the datetime data from mssql to just a date. I have searched the web and either I am not searching incorrectly or just don't understand. What I want to do is return the imlstrx_sql.eff_dt and imlstrx_sql.trx_dt formatted as ddmmmyyyy.
Any and all help is appreciated.

Here is what I am doing currently:

Code:
{

  $query = "select imlstrx_sql.item_no AS Item_Number, imitmidx_sql.item_desc_1 AS Description, imlstrx_sql.ser_lot_no AS Serial_Number,
                   imlstrx_sql.ord_no AS Order_Number, imlstrx_sql.eff_dt AS Production_Date, imlstrx_sql.trx_dt AS Ship_Date,
                   oehdrhst_sql.cus_no AS Customer_Number, oehdrhst_sql.bill_to_name AS Customer_Name, oehdrhst_sql.ship_to_name AS Ship_to_Name

                  FROM dbo.imlstrx_sql imlstrx_sql INNER JOIN dbo.oelinhst_sql oelinhst_sql
                  ON imlstrx_sql.line_no=oelinhst_sql.line_seq_no AND imlstrx_sql.ord_no=oelinhst_sql.ord_no
                  INNER JOIN dbo.imitmidx_sql imitmidx_sql ON imitmidx_sql.item_no=oelinhst_sql.item_no
                  INNER JOIN dbo.oehdrhst_sql oehdrhst_sql ON oelinhst_sql.ord_no=oehdrhst_sql.ord_no

                  WHERE imlstrx_sql.ser_lot_no='880-1279' AND oelinhst_sql.loc='AS'";
                  
  $result=odbc_exec($conn, $query);

  echo "<table border=\"1\"><tr>";

  $colName = odbc_num_fields($result);
  for ($j=1; $j<= $colName; $j++)
  {
    echo "<th>";
    echo odbc_field_name ($result, $j );
    echo "</th>";
  }

  while(odbc_fetch_row($result))
  {
    echo "<tr>";
    for($i=1;$i<=odbc_num_fields($result);$i++)
    {
      echo "<td>";
      echo odbc_result($result,$i);
      echo "</td>";
    }
    echo "</tr>";
  }

  echo "</td> </tr>";
  echo "</table >";

  odbc_close ($conn);
}
 
in mssql wrap the datefield with this
Code:
convert(varchar, datetimefieldname, 103)
[/code[

or in php
[code]
$datetime  = date('dmY', strtotime($mydatefield));
 
Thanks jpadie, I put in the mssql code and it worked perfectly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top