473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Calculating tim - easy for you! =)

Hello out there in the jungle...
=)

I found out that i can calculate the dates e.g

$today = strftime('%Y%m%d',mktime(0, 0, 0, date("m"), date("d"),
date("Y")));
$yesterday = strftime('%Y%m%d',mktime(0, 0, 0, date("m"), date("d") - 1,
date("Y")));
$dayBeforeYesterday = strftime('%Y%m%d',mktime(0, 0, 0, date("m"),
date("d") - 2, date("Y")));
$dayBeforeTheDayBeforeYesterday = strftime('%Y%m%d',mktime(0, 0, 0,
date("m"), date("d") - 2, date("Y")));

and so on........

This works even if we have the 1st of August $yesterday gives me the 31st
july.

Can I do this with times also??

e.g. Iit it now 17:06 an i want to make minus 20 min (like abopve minus 1
day) and I want the result to be 16:46.
I tried the above example, wit %H%M but it does not work?

Any ideas?

Thanks

:-X
Jul 17 '05 #1
3 1690
In article <8c**************************@posting.google.com >, georgios zakitraxis wrote:
Hello out there in the jungle...
=)

I found out that i can calculate the dates e.g


My favorite function: strtotime

Check it out in the manual :)
--
Tim Van Wassenhove <http://home.mysth.be/~timvw>
Jul 17 '05 #2
georgios zakitraxis wrote:
Can I do this with times also?? .... I tried the above example, wit %H%M but it does not work?


Yes, it does :)

$a_little_while_ago = strftime('%Y%m%d %H%M', mktime(date('H'),
date('i')-20, date('s'), date('m'), date('d'), date('y')));
--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
Jul 17 '05 #3
"georgios zakitraxis" <ef****@yahoo.de> wrote in message
news:8c**************************@posting.google.c om...
Hello out there in the jungle...
=)

I found out that i can calculate the dates e.g

$today = strftime('%Y%m%d',mktime(0, 0, 0, date("m"), date("d"),
date("Y")));
$yesterday = strftime('%Y%m%d',mktime(0, 0, 0, date("m"), date("d") - 1,
date("Y")));
$dayBeforeYesterday = strftime('%Y%m%d',mktime(0, 0, 0, date("m"),
date("d") - 2, date("Y")));
$dayBeforeTheDayBeforeYesterday = strftime('%Y%m%d',mktime(0, 0, 0,
date("m"), date("d") - 2, date("Y")));

and so on........


Unix timestamps are in general easier to work with as they're just numbers:

define(SECONDS_IN_A_DAY, 60 * 60 * 24);

$now = time();
$today = date("Y m d", $now);
$yesterday = date("Y m d", $now - SECONDS_IN_A_DAY);
$dayBeforeYesterday = date("Y m d", $now - SECONDS_IN_A_DAY * 2);
$dayBeforeTheDayBeforeYesterday = date("Y m d", $now - SECONDS_IN_A_DAY *
3);
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hans Gruber | last post by:
Hi all, I have been struggling with a problem all day, I have been unable to come up with a working solution. I want to write a function which takes 2 unix timestamps and calculates the...
13
by: Havatcha | last post by:
Does anyone know of a decent (free/easy to use) C++ library for manipulating matrices and caculating eigenvalues, eigenvectors and so on? I intend to add some Principal Component Analysis...
1
by: Megan | last post by:
quick summary: i'm having problems trying to group fields in a report in order to calculate percentages. to calculate percentages, i'm comparing the results from my grouped fields to the totals....
3
by: Ron Vecchi | last post by:
I need to calculate the age of a person based on a DateTime BirthDate I was thinking TimeSpan ts = DateTime.Now - BirthDate; //I can get the days but not years. // I could check each...
1
by: StormyTheCat | last post by:
Perhaps this is easy, but I'm new to C# am in need of some help. I need to embed a CRC value into an XML file to be able to detect when the data contained therin is corrupted. Calculating the...
38
by: jdcrief | last post by:
Complier: Visual C++ 2005 Express Edition The program I wrote will compile and execute, but the output is always the same, no matter what number is entered in for the radius of the circle. ...
3
by: Paul Aspinall | last post by:
Hi Can anyone recommend a suitable way of calculating distances between UK post codes?? Many websites do this, and I'm wondering if there is some standard code, and where the reference DB comes...
25
by: Umesh | last post by:
i want to calculate the time required to execute a program. Also i want to calcute the time remaining for the execution of the program. how can i do that? pl mention some good websites for...
25
by: Blaize | last post by:
Hi, I'm having an issue trying to calculate time. Its okay if the value does not exceed 24 hours otherwise I get a date and hours listed. For example, I have a loop which looks through a table...
4
by: Brian | last post by:
I have a 2000/2002 Access db that I use to collect and store my exercisetime using a form to enter. I wanted to see a summary of the total timefor each exercise so I have a subform that does this....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.