Apache time stamp needs to be reformatted. PHP gmdate()

The code below is working pretty well. It's displaying the next five days as links, but the formatting for the link isn't in the right format.

It's coming out as 2012-01-04

I need it to be 1012012

So need to switch around the order and remove all dashes.

Any suggestions?

Thanks,
mh
<?
				$curdate1111=gmdate("Y-m-d");
				for($rr=0;$rr<5;$rr++)
				{
					$SelectExpiredDate1="SELECT DATE_ADD(\"$curdate1111\", INTERVAL \"$rr\" DAY) as uppdate";
					$SelectExpiredDate1Rs=mysql_query($SelectExpiredDate1);
					$srow=mysql_fetch_object($SelectExpiredDate1Rs);
					//$nrow=ereg_replace("[^0-9]", "", $srow);
					?>
						<a href="search.php?Search=Closing=<?=$srow->uppdate;?>"><? echo strtoupper(date("l, m/d/Y",strtotime($srow->uppdate))); ?></a><br />
					<?
				}

			?>

Open in new window

LVL 7
MHenryAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Try one of these.  Date formatting is here: http://us3.php.net/manual/en/function.date.php  Note that your condensed formatting probably will not work in a MySQL datetime column.
$curdate1111=gmdate("jnY");
$curdate1111=gmdate("ndY");

Open in new window

0
idealwsCommented:
You can use something like this:

$newtimestamp = strtotime('2012-01-04');
echo date('mdY', $newtimestamp);

Open in new window


If your trying to do this after it is coming out of the DB. If not them the answer Dave gave above will work for you.

Regards,
Ray
0
Ray PaseurCommented:
Upgrade your knowledge base about how PHP and MySQL work with DATE and DATETIME information!  Read this article.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Now, let's have a look at this.  It is the ISO-8601 format date for the 4th of January of this year: 2012-01-04
Next, let's have a look at this.  It does not make any sense at all.  It's not the 4th of January: 1012012

So while, in fact, you can use strtotime() to convert '2012-01-04' into a timestamp, and you can use date('n01Y') to convert the timestamp into 1012012, there is no technically competent design pattern that accompanies such a conversion.  The professional approach would use ISO-8601 DATETIME strings for all internal representations of the dates and times, and would reformat the ISO values into "pretty" values for display to the client.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

MHenryAuthor Commented:
DaveBaldwin,

That didn't work, when I use that all the dates being displayed are the same date.

idealws,

Not sure how I would use that? I'm trying to get rid of the dashes. And I like the way the dates are being displayed now.


What I need is for the links that are displayed to stay like they are now:
  THURSDAY, 01/05/2012
  FRIDAY, 01/06/2012
  SATURDAY, 01/07/2012
  SUNDAY, 01/08/2012
  MONDAY, 01/09/2012


But the links that are associated with them need to read in m-d-y and the slashes need to be removed.

The column from the database is in string format.

Thanks,
mh

0
idealwsCommented:
You need to change the date to your variable:

$newtimestamp = strtotime($srow->uppdate);
echo date('mdY', $newtimestamp);

Open in new window


In your case I think it is as above.

Regards,
Ray
0
MHenryAuthor Commented:
idealws,

Sorry, I'm just not getting it. You mean like this?

<a href="search.php?Search=Closing=<?=$newtimestamp;?>"><? echo strtoupper(date("mdy",strtotime($newtimestamp))); ?>
0
idealwsCommented:
<?
				$curdate1111=gmdate("Y-m-d");
				for($rr=0;$rr<5;$rr++)
				{
					$SelectExpiredDate1="SELECT DATE_ADD(\"$curdate1111\", INTERVAL \"$rr\" DAY) as uppdate";
					$SelectExpiredDate1Rs=mysql_query($SelectExpiredDate1);
					$srow=mysql_fetch_object($SelectExpiredDate1Rs);
					//$nrow=ereg_replace("[^0-9]", "", $srow);
                                        $newtimestamp = strtotime($srow->uppdate);
                                        $thelinkdate = date('mdY', $newtimestamp);
					?>
						<a href="search.php?Search=Closing=<?=thelinkdate ;?>"><? echo strtoupper(date("l, m/d/Y",strtotime($srow->uppdate))); ?></a><br />
					<?
				}

			?>

Open in new window


try that and let me know if this is what you are looking for.

Regards,
Ray
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MHenryAuthor Commented:
idealws,

Now the link ends with thelinkdate and not a date. Just the word thelinkdate.



0
MHenryAuthor Commented:
idealws,

Yeah, just saw that I missed the $. Looks like it's working.

Thanks!

0
idealwsCommented:
Glad I could be of some help. Sorry I forgot the $ in the variable.

Regards,
Ray
0
idealwsCommented:
While your right this can be done using MySQL DATETIME strings as well as using a UNIX_TIMESTAMP the question wasn't how can I make this better it was how can I make it work. As for making it pretty for the client to see he has that already he wanted a simple solution to convert the data retrieved from the DB.

If you have a way in your mind to change the block of code he submitted to make it more professional as you stated, you should take the time to correct it and give the OP another method as well as promoting the book you have been promoting.

This is a quick fix and it works for the OP purpose. You are more than welcome to re-write it all to your likings.

Regards,
Ray
0
MHenryAuthor Commented:
Ray_Paseur.

And if you're sent a file from a vendor where the date is in a string format? Is there some reason I have to jump through all those hoops when all I'm doing is building a link?

Guess what, the database isn't optimized or tuned either. It's basically a flat file!

Sometimes in the real world, a situation is just dumped on you and you try to make the best of it.

Thanks to idealws, I can move on to the next fire I have to put out!

Best,
mh
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.