Textual date is displaying wrong day

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
Vaughanjb
Forum Commoner
Posts: 26
Joined: Thu Jul 08, 2010 4:56 am

Textual date is displaying wrong day

Post by Vaughanjb »

Hey Everybody,


I have the Day being displayed on my site and for some reason it's 2 days behind. Any help.

My code looks like this.

Code: Select all

<? echo date("l", strtotime($rowE['date'])); ?>
Any help would be great.

Thanks Vaughanjb
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Textual date is displaying wrong day

Post by requinix »

If it's displaying two days behind then $rowE['date'] is two days behind. Figure out why that is.
Vaughanjb
Forum Commoner
Posts: 26
Joined: Thu Jul 08, 2010 4:56 am

Re: Textual date is displaying wrong day

Post by Vaughanjb »

I've checked the dates. They are all correct.

For example

date = 08/09/2010
day should = Wednesday

but on my site it displays Monday

Any ideas?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Textual date is displaying wrong day

Post by pickle »

I'm guessing your date is day/month/year, but strtotime() is expecting month/day/year. The 9th of August was indeed a Monday.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Vaughanjb
Forum Commoner
Posts: 26
Joined: Thu Jul 08, 2010 4:56 am

Re: Textual date is displaying wrong day

Post by Vaughanjb »

Ahhhh, problem found. Thanks pickle.

Is there anyway to make it work from this date or is it best just to change the date during input?

Thanks

Vaughanjb
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Textual date is displaying wrong day

Post by pickle »

well generally only the United States uses the month/day/year format, so if you're asking users to enter the date & they're generally not from the US, that'll confuse them. If you're using a Javascript Datepicker, it doesn't really matter though. If it won't have an adverse affect on your users, I'd change it. Otherwise, keep it as is & just change it in code somewhere.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Vaughanjb
Forum Commoner
Posts: 26
Joined: Thu Jul 08, 2010 4:56 am

Re: Textual date is displaying wrong day

Post by Vaughanjb »

Cheers for all your advice pickle.
Just going to change it in the code.

Thanks again.
Your a credit to this site.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Textual date is displaying wrong day

Post by pickle »

Glad to help.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Textual date is displaying wrong day

Post by AbraCadaver »

FYI, the separators change the format:

Code: Select all

echo date("l", strtotime('08-09-2010'));
Wednesday
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply