PHP Get date from query

  • jordonshaw
  • Student
  • Student
  • User avatar
  • Posts: 96
  • Loc: Tennessee

Post 3+ Months Ago

I'm querying my DB and one of the field is a datetime field, which of course has the date and the time. I'm putting that into an array useing the mssql_fetch_array, with an loop to echo that back for each record. My question is, what is the best way to only display the date and not the date and time from that query.

So, this is what I currently have:
Code: [ Select ]
$course_set = mssql_query("SELECT Date from crsunits")
while ($course = mssql_fetch_array($course_set)) {
  echo "{$course['Date']}";
}
  1. $course_set = mssql_query("SELECT Date from crsunits")
  2. while ($course = mssql_fetch_array($course_set)) {
  3.   echo "{$course['Date']}";
  4. }


Right now, this displays the date and time and like I had said, I only want to display the date.

Thanks in advance.
Jordon
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • nexuslite
  • Newbie
  • Newbie
  • nexuslite
  • Posts: 10
  • Loc: Keizer, OR

Post 3+ Months Ago

substr is probably the easiest way to get just the date info.

Code: [ Select ]
$course_set = mssql_query("SELECT Date from crsunits");
while ($course = mssql_fetch_array($course_set)) {
    echo substr($course['Date'], 0, 10);;
}
  1. $course_set = mssql_query("SELECT Date from crsunits");
  2. while ($course = mssql_fetch_array($course_set)) {
  3.     echo substr($course['Date'], 0, 10);;
  4. }
  • jordonshaw
  • Student
  • Student
  • User avatar
  • Posts: 96
  • Loc: Tennessee

Post 3+ Months Ago

Thanks! That worked!

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 76 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.