Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-04-2007, 11:48 PM
Vitesse Vitesse is offline
 
Join Date: Jun 2005
Location: Essex, UK
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default php mktime question

Hi there,

Im doing something to display when a monthly newsletter will be released which is always the 1st of the month, so i've setup a plugin that i'm intending to use to put the date into a variable $nextmonth.

Problem is i cant seem to get the correct value.

This is what i've got at the minute:

Code:
$nextmonth = date("d/m/Y", mktime(0, 0, 0, 1, m+1, Y));
I know this doesnt work, as it always returns the value 01/01/2000 for some reason.

Effectively what i'm trying to achieve is that $nextmonth will currently have the value 01/02/2007 and if the date were say february now then it will be 01/03/2007 i.e. day will always be 01 month will be the next month and year will be next year if month is december. I've looked through lots of examples of this but cant really work out how to adapt it to what i need.

Anyone got any idea how to do this?
Reply With Quote
  #2  
Old 01-05-2007, 03:32 PM
noppid noppid is offline
 
Join Date: Mar 2003
Location: Florida
Posts: 1,875
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try this...

PHP Code:
$nextmonth date("d/m/Y"mktime(0001date("m")+1date("Y"))); 
the date function returns a number you can do the math on.
Reply With Quote
  #3  
Old 01-05-2007, 05:43 PM
Vitesse Vitesse is offline
 
Join Date: Jun 2005
Location: Essex, UK
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Noppid, the month seems to be doing what its supposed to but the date is coming out as 02/01/2007 rather than 01/02/2007

Any ideas?
Reply With Quote
  #4  
Old 01-05-2007, 06:47 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$nextmonth date('d/m/Y'mktime(000date('m') + 11date('Y'))); 
mktime uses month day year instead of the expected day month year
Reply With Quote
  #5  
Old 01-05-2007, 07:01 PM
noppid noppid is offline
 
Join Date: Mar 2003
Location: Florida
Posts: 1,875
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Vitesse View Post
Thanks Noppid, the month seems to be doing what its supposed to but the date is coming out as 02/01/2007 rather than 01/02/2007

Any ideas?
Simple adjustment.

PHP Code:
$nextmonth date("m/d/Y"mktime(0001date("m")+1date("Y"))); 
We just moved the m and d in the output format.
Reply With Quote
  #6  
Old 01-06-2007, 05:50 AM
Vitesse Vitesse is offline
 
Join Date: Jun 2005
Location: Essex, UK
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by noppid View Post
Simple adjustment.

PHP Code:
$nextmonth date("m/d/Y"mktime(0001date("m")+1date("Y"))); 
We just moved the m and d in the output format.
Fantasic, works perfectly, thanks Noppid & sirAdrian

got one question with regards to this, would it carry the year over if say for example current date was mid december would it then correctly display 01/01/08 ?
Reply With Quote
  #7  
Old 01-06-2007, 08:52 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

From the looks of it, no, because the year is not programmed to be one year ahead in your specified circumstances.
Reply With Quote
  #8  
Old 01-07-2007, 01:05 AM
Antivirus's Avatar
Antivirus Antivirus is offline
 
Join Date: Sep 2004
Location: Black Lagoon
Posts: 1,090
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

also, FYI if you were concerned with including a timestamp as well as the date, you would want to use the vbmktime function to ensure that the timestamp were in-synch with the recipient's selected timezone in their profile.
Reply With Quote
  #9  
Old 01-07-2007, 01:33 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yep, vbdate too...

BTW not sure if you applied what I said in my post or not, but if you didn't your results will be incorrect next month.
Reply With Quote
  #10  
Old 01-07-2007, 07:02 AM
Vitesse Vitesse is offline
 
Join Date: Jun 2005
Location: Essex, UK
Posts: 41
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dismounted View Post
From the looks of it, no, because the year is not programmed to be one year ahead in your specified circumstances.

How would that need to be altered to take the year into account?

Quote:
Yep, vbdate too...

BTW not sure if you applied what I said in my post or not, but if you didn't your results will be incorrect next month
It that simply a case of changing date to be vbdate or does the function word differently?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:44 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08169 seconds
  • Memory Usage 2,268KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (4)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete