Ninjakreborn Posted April 27, 2007 Share Posted April 27, 2007 This isn't help, it's more of thanks. I really never realized the poker of mktime and how easy it is to use. $signupdate = date(); $signupdate = strtotime($signupdate); $currentdueamount = "19.95"; $nextbillingdate = mktime(date("h", $signupdate), date("i", $signupdate), date("s", $signupdate), date("m", $signupdate)+1, date("d", $signupdate), date("y", $signupdate)); Yeah, basically if you have a date, and you just pass your format using an existing time stamp you keep your current data but you can do advanced calculations with it. So now it the time when I create a function using this code, over the weekend (DEFINITELY) I am thinking of it having a few variables, so you can set which ones you want to increase/decrease (seconds, hours, months, years), or whatever. This thing can do ANY date calculations very easily. It's a little "repetitive" having to put in the same time stamp over and over again, so when I Create a function I will have it where you can pass the time stamp once and it does the rest. Then you just feed it (like an array or something) of what calculations you want to do (add to month, or year, or subtract from seconds), or something. I can definitely come up with something for this. Quote Link to comment https://forums.phpfreaks.com/topic/48957-mktime/ Share on other sites More sharing options...
Ninjakreborn Posted April 27, 2007 Author Share Posted April 27, 2007 <?php // function Advance Time // Parameters // @ timestamp - Timestamp: (timestamp of time you want to advanced // @ String - p1modifier (part 1 modifier) - this is what you want to modify // Possible Values (hours(hours, h, hour), minutes (minutes,min,mins,minute), seconds, months, // days, years) They can be entered in, with multiple variations // @ String - p2modifier (Part 2 modifier) The alteration to the p1 modifier // possible values - (It can be anything with addition or subtraction function advancetime($timestamp, $p1modifier="", $p2modifier="") { // make sure variables where set (they are all required if ($timestamp == "") { return false; } if ($p1modifier == "") { return false; } if ($p2modifier == "") { return false; } if ($p1modifier == "h" || $p1modifier == "hours" || $p1modifer == "hour") { return mktime(date("h", $timestamp) . $p1modifier . $p2modifier, date("i", $timestamp), date("s", $timestamp), date("m", $timestamp), date("d", $timestamp), date("y", $timestamp)); }elseif ($p1modifier == "minutes" || $p1modifier == "mins" || $p1modifier == "min") { return mktime(date("h", $timestamp), date("i", $timestamp) . $p2modifier, date("s", $timestamp), date("m", $timestamp), date("d", $timestamp), date("y", $timestamp)); }elseif ($p1modifier == "seconds" || $p1modifier == "secs" || $p1modifier == "sec") { return mktime(date("h", $timestamp), date("i", $timestamp), date("s", $timestamp) . $p2modifier, date("m", $timestamp), date("d", $timestamp), date("y", $timestamp)); }elseif ($p1modifier == "months" || $p1modifier == "month" || $p1modifier == "mo") { return mktime(date("h", $timestamp), date("i", $timestamp), date("s", $timestamp), date("m", $timestamp) . $p2modifier, date("d", $timestamp), date("y", $timestamp)); }elseif ($p1modifier == "day" || $p1modifier == "days" || $p1modifier == "date") { return mktime(date("h", $timestamp), date("i", $timestamp), date("s", $timestamp), date("m", $timestamp), date("d", $timestamp) . $p2modifier, date("y", $timestamp)); }elseif ($p1modifier == "years" || $p1modifier == "year") { return mktime(date("h", $timestamp), date("i", $timestamp), date("s", $timestamp), date("m", $timestamp), date("d", $timestamp), date("y", $timestamp) . $p2modifier); } }// end function // testing/debugging page $signupdate = date("m/d/Y"); $signupdate = strtotime($signupdate); echo "Date: " . date("m/d/Y", $signupdate); echo "<br />Date Timestamp: " . $signupdate; $currentdueamount = "19.95"; echo "<br />Current Amount Due " . $currentdueamount; $nextbillingdate = advancetime($signupdate, "months", "-1"); echo "<br /> Next Billing Date: " . $nextbillingdate; $nextbillingdate = date("m/d/y", $nextbillingdate); echo "<br /> Next Billing Date(date): " . $nextbillingdate; ?> That function there is what I just came up with but it's not working. I created it, then rewrote a few parts that didn't make sense, and a few mistakes I saw, when it looked right I tested it, and it's not doing any calculations on date. Any advice? Quote Link to comment https://forums.phpfreaks.com/topic/48957-mktime/#findComment-239879 Share on other sites More sharing options...
Ninjakreborn Posted April 30, 2007 Author Share Posted April 30, 2007 Any ideas on why the function isn't working properly Quote Link to comment https://forums.phpfreaks.com/topic/48957-mktime/#findComment-241603 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.