PHP Get date from query

  • jordonshaw
  • Student
  • Student
  • User avatar
  • Joined: Dec 30, 2008
  • Posts: 91
  • Loc: Tennessee
  • Status: Offline

Post February 10th, 2010, 2:27 pm

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
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post February 10th, 2010, 2:27 pm

  • nexuslite
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Feb 11, 2010
  • Posts: 10
  • Loc: Keizer, OR
  • Status: Offline

Post February 11th, 2010, 5:35 am

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
  • Joined: Dec 30, 2008
  • Posts: 91
  • Loc: Tennessee
  • Status: Offline

Post February 11th, 2010, 8:35 am

Thanks! That worked!

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 112 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
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.