[SOLVED] Reformat A Date
Moderator: General Moderators
[SOLVED] Reformat A Date
I have a date stored in a variable $date_assigned. It contains ("m-d-Y") format.
I want to print out this date but only showing it in the ("m-d") format, basically I do not want the year to show.
I want to print out this date but only showing it in the ("m-d") format, basically I do not want the year to show.
How do you get the date? If you get it via a query use a mysql function to give you the format you need.
http://dev.mysql.com/doc/refman/5.0/en/ ... tions.html
http://dev.mysql.com/doc/refman/5.0/en/ ... tions.html
Hmhmhm...
Ok, this is how it goes.
I have a page that prints out a table of data from a database. It prints the following fields.
$policy_number
$first_name
$date_assigned
$date_assigned being a date that was stored into the database when the case for the user was assigned. When the date was stored it was stored like this date("m-d-Y");
I want to print it out of the database now but I do not want to have the year print out, just the month and day.
I figured this was an easy one, I dunno.
Help, Please?
I have a page that prints out a table of data from a database. It prints the following fields.
$policy_number
$first_name
$date_assigned
$date_assigned being a date that was stored into the database when the case for the user was assigned. When the date was stored it was stored like this date("m-d-Y");
I want to print it out of the database now but I do not want to have the year print out, just the month and day.
I figured this was an easy one, I dunno.
Help, Please?
- blacksnday
- Forum Contributor
- Posts: 252
- Joined: Sat Jul 30, 2005 6:11 am
- Location: bfe Ohio :(
I insert and format dates using
which shows like: 2006-01-19 11:39:20
And then retrieve and format using
which shows like: 01-19-2006
So using my example, to not have the year show you would
just take out the -$year from the $date
Code: Select all
function insertDate()
{
$timestamp = time()+date("Z");
$time = gmdate("Y-m-d H:i:s",$timestamp);
return $time;
}And then retrieve and format using
Code: Select all
function niceDate($daterow)
{
$day = substr($daterow, 8, 2);
$month = substr($daterow, 5, 2);
$year = substr($daterow, 0, 4);
$date = "$month-$day-$year";
return $date;
}So using my example, to not have the year show you would
just take out the -$year from the $date
- blacksnday
- Forum Contributor
- Posts: 252
- Joined: Sat Jul 30, 2005 6:11 am
- Location: bfe Ohio :(
Because I dont allow flooding. So I still need the time with the date.hawleyjr wrote:why not format the date the way you want it in your query?
And I have other uses for full date/time....
I would rather have all info in one row and use whats needed when needed
compared to many rows with seperate info.
I believe he/she is regarding a date field not date time.
IMHO ~ MySQL functions are extremely underrated.
When the date was stored it was stored like this date("m-d-Y");
I disagree; why not let mysql do the work? By doing it via a PHP function you are just adding extra unnecessary work.I would rather have all info in one row and use whats needed when needed
compared to many rows with seperate info.
IMHO ~ MySQL functions are extremely underrated.
- blacksnday
- Forum Contributor
- Posts: 252
- Joined: Sat Jul 30, 2005 6:11 am
- Location: bfe Ohio :(
They were asking how to format a date.hawleyjr wrote:I believe he/she is regarding a date field not date time.
When the date was stored it was stored like this date("m-d-Y");
My post showed how to format a date regardless of how it was stored.
p.o.hawleyjr wrote:I disagree; why not let mysql do the work? By doing it via a PHP function you are just adding extra unnecessary work.I would rather have all info in one row and use whats needed when needed
compared to many rows with seperate info.
INHO ~ MySQL functions are extremely underrated.
personal opinion
MySQL Format
I think I would like to see an example of how to format the date using MySQL.
Anyone?
Anyone?
Gladly 
http://dev.mysql.com/doc/refman/5.0/en/ ... #id3127979
This query will give you a record id and a date formatted as month [space] Day of the month
http://dev.mysql.com/doc/refman/5.0/en/ ... #id3127979
Code: Select all
SELECT id,DATE_FORMAT(date_field,'%m %d') as some_date_name from my_table