Welcome to WebmasterWorld Guest from 18.104.22.168
If I leave the variable untouched the page works but I would like to have
Jan 01 instead of yyyy-01-01
So I have been trying to get it to work using
$variable = mysql_result($qResult,$j,"VariableField");;
$variable = strftime("%b %d" ,$variable);
but when the page executes all the dates appear as the same.
Is strftime() the way forward or should I be using a function that I dont know of. Thanks for your time.
As said above it worked for the first one and then repeats that value for the rest.
Well that can't be caused by the formatting, that's caused by the data, so your problem must be in your queries. I would guess that you are returning the same result set every time you loop through and you are printing out the first row every time.
Can you put the query outside the loop and return a whole result set and then loop through it using mysql_fetch_array()?
I am working towards a solution at the moment where I make extra SELECTS in the sql. Seems wastefull but at the moment I can get it to work with full month name (wanted MMM) and a day format (wanted dd).
I thought as you had already extracted the date in full you could format its output, perhaps i want too much :)
I will look at all your suggestions 8 am tommorrow. I'm off to the pub now. (9:30pm, bring on the lager)
Is $variable a valid timestamp?
Yes it is set to DATE, not DATETIME.
If I leave it as the $variable straight from the
it works, all the repeats are the correct dates in full yyyy-mm-dd format. It just throws a mental when I try to reformat it in PHP using the strftime(). Perhaps that is it, it is not a time as such? If so how does one go abvout reformatting it?
By creating extra selects eg MONTHNAME and DAYNAME I can get it to work OK, but that is not the exact format I want and seems wasteful on resources, eg adding extra to the SQL for information that is already being used in a different format sucessfully.
Still largely baffled and wondering if the users can deal with :
"April Wednesday" instead of "Apr 02" :)
Alternately you could try date() with strtotime() like this: $variable = date("M j" ,strtotime($variable));
I'm not sure why but it seems I must have something formatted improperly whenever I use a DATE field in MYSQL because whenever I try to display it I end up having to use date and strtotime to make it work so I won't say that's the best way to get what you're after - I just know it worked for me. ;)
$string = $variable;
$stringArray = explode("-", $string);
$date = mktime(0,0,0,$stringArray,$stringArray,$stringArray);
$convertedDate = date("M j", $date);
Then call the convertedDate variable. By changing the M and J in accordance with DATE_FORMAT depending on what you are after.
Thanks all for helping me along.