Solved

PHP: date + 2 minutes

Posted on 2006-06-18
7
285 Views
Last Modified: 2012-08-13
Hi!

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:
20060601000159000



Thanks.
0
Comment
Question by:excinc
  • 3
  • 3
7 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
you need to split the string into it's parts, and use mktime to create a true date/time value:
http://lu.php.net/manual/en/function.mktime.php

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:
http://lu2.php.net/date
date("YmdHis") . "000"
0
 

Expert Comment

by:rucpat
Comment Utility
Hi,

you can use strptime

http://us2.php.net/manual/en/function.strptime.php

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

http://us2.php.net/manual/en/function.strftime.php

to generate the changed string.
0
 

Author Comment

by:excinc
Comment Utility
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
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
>Won't  work :D
what error?
0
 

Author Comment

by:excinc
Comment Utility
Warning: Wrong parameter count for mktime() in E:\Hotcircle\wwwroot\1_jarkan\testausta_2_3alkuaineet.php on line 8
19700101020000
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
Comment Utility
obviously:
>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 ) ))  );
0
 

Author Comment

by:excinc
Comment Utility
angelIII, thanks


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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now