Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 836 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

PHP Calendar Displaying Wrong Date

Thread title: PHP Calendar Displaying Wrong Date
Reply    
    Thread tools Search this thread Display Modes  
03-27-2011, 08:23 PM
#1
mjwalsh is offline mjwalsh
mjwalsh's Avatar
Status: I love this place
Join date: Dec 2007
Location:
Expertise: Programming - Sys Admin
Software: Dreamweaver - Notepad++
 
Posts: 638
iTrader: 14 / 100%
 

mjwalsh is on a distinguished road

  Old  PHP Calendar Displaying Wrong Date

At this point I have coding goggles and am certain I must be missing something dumb.. My calendar is displaying that the first day of March was on a Wednesday, however it wasn't, it was on a Tuesday. Any ideas on what could be causing this? ( I already verified that the servers timezone was set correct )

PHP Code:
 $cal_date  time(); 
  
 
$cal_day   date('d'$cal_date); 
 
$cal_month date('n'$cal_date); 
 
$cal_year  date('Y'$cal_date); 
  
 
$first_day mktime(000$cal_month1$cal_year); 
  
 
$title     date('F'$first_day); 
  
 
$cal_day_of_week date('D'$fist_day); 
Basically "$cal_day_of_week" is returning as "Wed" when it should return as "Tue".

03-27-2011, 09:01 PM
#2
scrappy is offline scrappy
scrappy's Avatar
Status: Member
Join date: Aug 2006
Location: Newcastle upon Tyne
Expertise:
Software:
 
Posts: 172
iTrader: 1 / 100%
 

scrappy is on a distinguished road

Send a message via MSN to scrappy

  Old

Originally Posted by mjwalsh View Post
$cal_month = date('n', $cal_date);
Should that not read:

PHP Code:
$cal_month date('m'$cal_date); 

03-28-2011, 05:51 AM
#3
mjwalsh is offline mjwalsh
mjwalsh's Avatar
Status: I love this place
Join date: Dec 2007
Location:
Expertise: Programming - Sys Admin
Software: Dreamweaver - Notepad++
 
Posts: 638
iTrader: 14 / 100%
 

mjwalsh is on a distinguished road

  Old

Both n and m would be a proper response to what it's used for. Inside mktime it needs a value 1-12 for the depending month, n displays the month without a 0 if the value is less than 10, m uses a zero. IE: m would echo 03 whereas n would just echo 3.

Reply With Quote
03-28-2011, 05:55 AM
#4
mjwalsh is offline mjwalsh
mjwalsh's Avatar
Status: I love this place
Join date: Dec 2007
Location:
Expertise: Programming - Sys Admin
Software: Dreamweaver - Notepad++
 
Posts: 638
iTrader: 14 / 100%
 

mjwalsh is on a distinguished road

  Old

I just realized

PHP Code:
 $cal_day_of_week date('D'$fist_day); 
The value "$fist_day" is spelled wrong, corrected spelling and now it works Coding goggles suck!

05-09-2011, 07:09 PM
#5
unikorndesigns is offline unikorndesigns
unikorndesigns's Avatar
Status: Junior Member
Join date: May 2011
Location:
Expertise: Web Designing and Development
Software: Photoshop, Dreamweaver and etc
 
Posts: 41
iTrader: 0 / 0%
 

unikorndesigns is on a distinguished road

  Old

hmmm......why dont ya use jQuery instead of PHP for this purpose??

Reply With Quote
05-10-2011, 12:26 AM
#6
Gaz is offline Gaz
Gaz's Avatar
Status: Request a custom title
Join date: Apr 2007
Location: UK
Expertise: Code & Programming
Software: Coda, TextMate, Sublime 2
 
Posts: 2,097
iTrader: 26 / 100%
 

Gaz will become famous soon enough Gaz will become famous soon enough

Send a message via Skype™ to Gaz

  Old

What if the user has JavaScript turned off? PHP is 100% to work on browsers.

Reply With Quote
06-19-2011, 05:37 AM
#7
scriptbazaar is offline scriptbazaar
Status: I'm new around here
Join date: Nov 2008
Location:
Expertise:
Software:
 
Posts: 12
iTrader: 0 / 0%
 

scriptbazaar is on a distinguished road

  Old

Originally Posted by Gaz View Post
What if the user has JavaScript turned off? PHP is 100% to work on browsers.
true but you have to refresh the page to see the end result where as in jquery its instant without any page reloads.

Reply With Quote
06-19-2011, 10:15 PM
#8
Wildhoney is offline Wildhoney
Wildhoney's Avatar
Status: Request a custom title
Join date: Feb 2006
Location: Nottingham
Expertise:
Software:
 
Posts: 1,648
iTrader: 18 / 95%
 

Wildhoney is on a distinguished road

Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney

  Old

fist_day sounds like some dodgy porno. I think there's some Freudian stuff going on here, but my psychoanalysis mind eludes me!

As for the suggestion of JavaScript, I'd personally use PHP to create all the nodes relating to the calendar, and then hook in JavaScript to make it dynamic; such as switching the months, and selecting the desired date.

Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed