PHP: date + 2 minutes

Posted on 2006-06-18
Last Modified: 2012-08-13

I have date and the format is:

$date = '20060531235959000';

How can I add for example two minutes to that? So the result should be like:

Question by:excinc
  • 3
  • 3
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16932199
you need to split the string into it's parts, and use mktime to create a true date/time value:

with mktime, use all parameters to 0 except the minute parameter, and add the resulting value to the above value.
use date() function to format that value to your format:
date("YmdHis") . "000"

Expert Comment

ID: 16932205

you can use strptime 

to parse your string, then add 2 minutes and use strftime

to generate the changed string.

Author Comment

ID: 16932210
Yeah, I tried that but I didn't get it work.

I tried something like this:

$date = '20060516235959000';

$result = date("YmdHis", (mktime (0,0,0,substr ( $date, 4, 2 ),substr ( $date, 6, 2 ),substr ( $date, 0, 4 ),substr ( $date, 8, 2 ),substr ( $date, 10, 2 ),substr ( $date, 12, 2 ))));

Won't  work :D
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16932220
>Won't  work :D
what error?

Author Comment

ID: 16932224
Warning: Wrong parameter count for mktime() in E:\Hotcircle\wwwroot\1_jarkan\testausta_2_3alkuaineet.php on line 8
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 50 total points
ID: 16932242
>int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )
you put the values in the wrong order....

$result = date("YmdHis", (mktime (substr ( $date, 8, 2 ),substr ( $date, 10, 2 ),substr ( $date, 12, 2 ),substr ( $date, 4, 2 ),substr ( $date, 6, 2 ),substr ( $date, 0, 4 ) ))  );

Author Comment

ID: 16932253
angelIII, thanks

hrrr... coffing... ugh.. rookie mistake :)

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question