473,569 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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")));
$dayBeforeYeste rday = strftime('%Y%m% d',mktime(0, 0, 0, date("m"),
date("d") - 2, date("Y")));
$dayBeforeTheDa yBeforeYesterda y = 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 1696
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.d e> wrote in message
news:8c******** *************** ***@posting.goo gle.com...
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")));
$dayBeforeYeste rday = strftime('%Y%m% d',mktime(0, 0, 0, date("m"),
date("d") - 2, date("Y")));
$dayBeforeTheDa yBeforeYesterda y = 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_DA Y);
$dayBeforeYeste rday = date("Y m d", $now - SECONDS_IN_A_DA Y * 2);
$dayBeforeTheDa yBeforeYesterda y = date("Y m d", $now - SECONDS_IN_A_DA Y *
3);
Jul 17 '05 #4

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

Similar topics

4
4444
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 difference. I want it to return the difference in years, months, days, hours, minutes and seconds (a complete summary). Keeping into account of course...
13
5847
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 functionality to some software. Any recommendations appreciated.
1
2504
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. first, let me say that this is a really long post. i wasn't sure how much information/ background to provide, so i thought more was better than...
3
12930
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 year from their year of birth, count the days in the year and compare with the days returned from timespan
1
5268
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 CRC on the DataSet (or an XML structure) has been the big problem. This seems like a fairly common problem but I have been unable to find the...
38
5885
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. Someone please help! I am extremely new at this, as you can probably tell. What am I missing with the code below? #include "stdafx.h"
3
2585
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 from? Any help/advice appreciated Thanks
25
4997
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 learning advanced C.thx.
25
3185
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 and adds up the time spent. Dim TempCount As Date Dim DEVCount As Date Do TempCount = rst!wtime
4
2418
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. Only issue is thatwhen I go over 24 hrs I get the infamous summing time issue. It would bereally easy if Access used the Excel :nn format, but it...
0
7614
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8125
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7974
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.