Jump to content

convert mysql date format "2007-04-01" to "April 2007" output


Recommended Posts

hey guys quicky

 

whats the best way to get a my mysql stored date in the format "2007-04-01" to output on screen with php help as April 2007.

The day is not important, just the month and year in a readable fashion.

 

thanks x

forum helper?

 

always amazes me people consider links help, if i wanted links i could of googled it and spent half an hour trawling through pages and reading up on it. If all people do is dump links then ask yourself whats the point of ths forum php help?

 

i could be wrong but my idea of a helpfull site is a link perhaps, a real exmaple to the problem and a reason this is the best practice to do it.

 

Also perhaps i should of explained, the date is already in a complex select statement, so is in a $row_qryData['expiredate'], I am not simply polling mysql for this date alone.

forum helper?

 

always amazes me people consider links help, if i wanted links i could of googled it and spent half an hour trawling through pages and reading up on it. If all people do is dump links then ask yourself whats the point of ths forum php help?

 

i could be wrong but my idea of a helpfull site is a link perhaps, a real exmaple to the problem and a reason this is the best practice to do it.

 

Also perhaps i should of explained, the date is already in a complex select statement, so is in a $row_qryData['expiredate'], I am not simply polling mysql for this date alone.

 

It always amazes me how people want things handed to them on a silver platter. If you want help, expect to be ready to help yourself first.

 

You never asked for an example. You asked for the best way to accomplish something and I provided you reference to what I believed to be the best ways. Might I also note, I provided you with links to manuals from the languages you are using. It doesn't get any better than that (examples they offer etc).

 

Aslo, might I add, per forum guidelines, it is ACTUALLY recommended to google it:

http://www.phpfreaks.com/forums/index.php/topic,6264.0.html (I recommend you read them)

forum helper?

 

always amazes me people consider links help, if i wanted links i could of googled it and spent half an hour trawling through pages and reading up on it. If all people do is dump links then ask yourself whats the point of ths forum php help?

 

i could be wrong but my idea of a helpfull site is a link perhaps, a real exmaple to the problem and a reason this is the best practice to do it.

 

Also perhaps i should of explained, the date is already in a complex select statement, so is in a $row_qryData['expiredate'], I am not simply polling mysql for this date alone.

 

It always amazes me how people want things handed to them on a silver platter. If you want help, expect to be ready to help yourself first.

 

You never asked for an example. You asked for the best way to accomplish something and I provided you reference to what I believed to be the best ways. Might I also note, I provided you with links to manuals from the languages you are using. It doesn't get any better than that (examples they offer etc).

your right, lets close the site, save money and all read manuals.

your right, lets close the site, save money and all read manuals.

 

What a petty argument.

 

A better suggestion:

Lets take help for what it is; help.

 

If you don't like the help provided, fine. There is no need to act immature about it and make ignorant statments.

Just to confirm, the exidting date is a string "2007-04-01" and not a timestamp or other date field format?

 

rich its stored as date in mysql, and i belive its this format yes mate.

I think the best way is to write some code using

 

$year  = substr($row_qryCompanyDetails['CompanyExpire'],0,4);
$month = substr($row_qryCompanyDetails['CompanyExpire'],5,2);

 

and then do some magic on it to compare and output the correct month string?

this is what i use.

 

<?php
echo date("M, Y",strtotime($date)); 
// if $date was "2007-08-29"
//prints Aug, 2007;
// or use this 
echo date("F, Y",strtotime($date)); 

//prints August, 2007;
//replace the $date with whatever the result from your query is for the date.
?>

 

short and sweet.

forum helper?

 

always amazes me people consider links help, if i wanted links i could of googled it and spent half an hour trawling through pages and reading up on it. If all people do is dump links then ask yourself whats the point of ths forum php help?

 

i could be wrong but my idea of a helpfull site is a link perhaps, a real exmaple to the problem and a reason this is the best practice to do it.

 

Also perhaps i should of explained, the date is already in a complex select statement, so is in a $row_qryData['expiredate'], I am not simply polling mysql for this date alone.

If a mod feels I'm out of line, by all means edit this post, but this response was way out of line.  You asked a question, someone gave you the information to solve your problem with two different methods.  In the PHP documentation, all it took was a ctrl + f -> "mysql" and you get this code:

// format MySQL DateTime (YYYY-MM-DD hh:mm:ss) using date()

function datetime($syntax,$datetime) {
    $year = substr($datetime,0,4);
    $month = substr($datetime,5,2);
    $day = substr($datetime,8,2);
    $hour = substr($datetime,11,2);
    $min = substr($datetime,14,2);
    $sec = substr($datetime,17,2);
   
    return date($syntax,mktime($hour,$min,$sec,$month,$day,$year));
}

 

The link to the MySQL documentation contains six examples less then half a page down.  Both of them were obtainable by you in less than 15 seconds, yet you decided to take that time to reply and throw help back in someone's face?

 

It's irrelevant that the date is already returned in a query as you can always modify the query to return different or additional information.  As thorpe pointed out, it's almost always more efficient to have the database engine perform the work for you.

 

I suggest you learn some basic manners and how to take a little initiative before you attempt to do much programming; if you do not learn how to apply a general example to your specific problem you will extremely hamper your ability to become a proficient programmer and problem solver.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.