Jump to content

[SOLVED] mktime to strtotime convert if possible


Recommended Posts

Hi,

 

I would like to if possible to convert the mktime to strtotime, I have looked at the strtotime on php.net and it went right over my head, so I was wonder if someone could help me to convert the below from mktime into strtotime if it possible

 

The below is the from the script I am trying to get to work

 

$showMonth = date("F Y", mktime(0,0,0,$Month,1,$Year));
$numDays = date("t",mktime(0,0,0,$Month,1,$Year));
$startDay = date("w",mktime(0,0,0,$Month,1,$Year));

$prevMonth = date("m", mktime(0,0,0,($Month - 1), 01, $Year));
$prevYear = date("Y", mktime(0,0,0,($Month - 1), 01, $Year));
$nextMonth = date("m", mktime(0,0,0,($Month + 1), 01, $Year));
$nextYear = date("Y", mktime(0,0,0,($Month + 1), 01, $Year));

$todaysDay = date("w", mktime(0,0,0,$Month, $q, $Year));

if ( date("m", mktime(0,0,0,$Month, $q, $Year)) == date("m", mktime(0,0,0,$Month, ($q - 7), $Year)) ) {

 

Regards,

Garry

strtotime by design ins't meant to be used  on none user input except for when you are doing the

"+1 Day", "-1 Week" etc varients.  Its primary purpose is to take a formated date (like mm/dd/yyyy or mm-dd-yyyy or yyyy-mm-dd) and spit out a unix time stamp with association to what it knows about the input.

 

in your case you are  setting times to the begining of a month for the most part

the $preYear,$nextmonth can be handled by saying

 

$prevYear = date("Y", strtotime("-1 year",$Year));

 

however from a amount of processing time that would take more as your taking a valid time item (year) and treating it like a raw string just to convolute it to put it back into a time, it would also probably return jan 1 12:00 am on the previous year not what you want exactly (although you just want the Y part of it)

 

 

as you can see in this case its not much help in the long run actually slower

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.