Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. php 7.4.14 convert smalldatetime to string for html display

php 7.4.14 convert smalldatetime to string for html display

Scheduled Pinned Locked Moved Web Development
databasehelpphphtmlsql-server
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jkirkerx
    wrote on last edited by
    #1

    I'm stumped, and sort of shocked that PHP didn't like the value or type. $sold_date in the the sql server table is defined as smalldatetime. In the table, the value is 2/7/2008 I tried $sold_date->format('m-d-y') and it didn't like it. I also searched and searched, and just found generic anwsers Fatal error: Uncaught Error: Object of class DateTime could not be converted to string in C:\App\Dev\PCAD\project_update.phtml:427 Stack trace: #0 {main} thrown in C:\App\Dev\PCAD\project_update.phtml on line 427

    echo "

    $sold_date

    ";

    My database call is

    $row_proj = sqlsrv_fetch_array($res_proj);
    $projectNumber = $row_proj[0];
    $proj_stage = $row_proj[1];
    $version_no = $row_proj[2];
    $customerNumber = $row_proj[3];
    $sold_date = $row_proj[4]; // FIXME - convert smalldatetime to string
    $sales_no = $row_proj[5];
    $swan_job = $row_proj[6];

    If it ain't broke don't fix it Discover my world at jkirkerx.com

    Richard DeemingR 1 Reply Last reply
    0
    • J jkirkerx

      I'm stumped, and sort of shocked that PHP didn't like the value or type. $sold_date in the the sql server table is defined as smalldatetime. In the table, the value is 2/7/2008 I tried $sold_date->format('m-d-y') and it didn't like it. I also searched and searched, and just found generic anwsers Fatal error: Uncaught Error: Object of class DateTime could not be converted to string in C:\App\Dev\PCAD\project_update.phtml:427 Stack trace: #0 {main} thrown in C:\App\Dev\PCAD\project_update.phtml on line 427

      echo "

      $sold_date

      ";

      My database call is

      $row_proj = sqlsrv_fetch_array($res_proj);
      $projectNumber = $row_proj[0];
      $proj_stage = $row_proj[1];
      $version_no = $row_proj[2];
      $customerNumber = $row_proj[3];
      $sold_date = $row_proj[4]; // FIXME - convert smalldatetime to string
      $sales_no = $row_proj[5];
      $swan_job = $row_proj[6];

      If it ain't broke don't fix it Discover my world at jkirkerx.com

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      jkirkerx wrote:

      I tried $sold_date->format('m-d-y') and it didn't like it.

      How did you try it? I suspect you'd need to use the "complex" syntax[^] to embed that within a string:

      echo "
      <td class='text-align-center'>
      <p class='margin-text-indent'> {$sold_date->format('m-d-y')} </p>
      </td>";

      If that doesn't work, what error do you get?


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      J 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        jkirkerx wrote:

        I tried $sold_date->format('m-d-y') and it didn't like it.

        How did you try it? I suspect you'd need to use the "complex" syntax[^] to embed that within a string:

        echo "
        <td class='text-align-center'>
        <p class='margin-text-indent'> {$sold_date->format('m-d-y')} </p>
        </td>";

        If that doesn't work, what error do you get?


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        J Offline
        J Offline
        jkirkerx
        wrote on last edited by
        #3

        Oh that works! I would figured it out eventually, maybe within 3 months ;) Just read the link, did not know that. I was thinking perhaps I had to preprocess that variable before echoing it out to the presentation layer. Well that solves another 500 errors in this project, about 1000 more to go. Thanks Richard, really appreciate the help. This project is really beating me up mentally, but it will be worth it in the end.

        If it ain't broke don't fix it Discover my world at jkirkerx.com

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups