Basic Date Formatting Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dgny06
Forum Commoner
Posts: 25
Joined: Thu Jun 14, 2007 11:35 pm

Basic Date Formatting Question

Post by dgny06 »

I know it is a basic question, but let's say that I have a variable called "gameDate" that returns a date from a database. The output is coming back as 2010-02-02 00:00:00, however I would like to remove the "00:00:00" from the string. Since I am not formatting a date, but rather the variable that returns a date, can you please let me know how to do this?

Thanks in advance!!!
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Basic Date Formatting Question

Post by s.dot »

http://www.php.net/manual/en/datetime.format.php

Or what I would do is turn it into a timestamp and use the date() function to format it.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Basic Date Formatting Question

Post by pickle »

Change your query to use the DATE() function: http://dev.mysql.com/doc/refman/5.1/en/ ... ction_date

Or, failing that, use strtotime:

Code: Select all

$justDate = date('Y-m-d',strtotime($dateTimeFromDB));
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply