473,386 Members | 1,745 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,386 software developers and data experts.

Age to seconds calculater

wadro21
12
Hello all,

i am writing a tiny program as an excersize to take someones age and determine how many seconds old they are. This is the php to what i have so far:
Expand|Select|Wrap|Line Numbers
  1. <?php  
  2.  
  3. $action = $_POST['action'];
  4. $name= $_POST['name'];
  5. $month=$_POST['month'];
  6. $day= $_POST['day'];
  7. $year= $_POST['year'];
  8. $time= $_POST['time'];
  9. $m= ("$month,$day");
  10. $calculate= "$month, $day, $year, $time";
  11.  
  12. ?>   
  13.  
  14. <?php
  15.    echo("Hello, $name ! ");
  16.    echo("You were born on $month $day, $year at $time o'clock".'</br>');
  17.    echo('you are ');
  18.    echo time() - strtotime ("$m, $year, $time, $year");
  19.    echo (' seconds old!');
  20.  
  21.  
  22.    ?>
  23.  
The problem is that it doesnt calculate properly. I think this line: echo time() - strtotime ("$m, $year, $time, $year");
is the problem, i just dont know how to fix it. Please help!!!!

Thanks,
Aug 23 '07 #1
6 1592
pbmods
5,821 Expert 4TB
Heya, Wadro. Welcome to TSDN!

What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Aug 23 '07 #2
wadro21
12
here is the out put:
Hello, ! You were born on jun 18, 1982 at 11:00 o'clock
you are 1187893914 seconds old!

The seconds that are calculating (1187893914) are wrong. as i refresh the screen the seconds are updated they just dont have the write answer. i dont know were it gets the 1187893914 from.

Thanks,
Aug 23 '07 #3
pbmods
5,821 Expert 4TB
Heya, Wadro.

I'll bet that your script is outputting the number of seconds since December 31, 1969 11:59:59.

Try this instead:
Expand|Select|Wrap|Line Numbers
  1. echo time() - strtotime("$year-$month-$day $time");
  2.  
Aug 23 '07 #4
wadro21
12
Heya, Wadro.

I'll bet that your script is outputting the number of seconds since December 31, 1969 11:59:59.

Try this instead:
Expand|Select|Wrap|Line Numbers
  1. echo time() - strtotime("$year-$month-$day $time");
  2.  

Thats it! Thanks for quick reply!
below is the entire code for anyone who is interested. It's a very small app but good to play with.
Expand|Select|Wrap|Line Numbers
  1. <?php  
  2.  
  3. $action = $_POST['action'];
  4. $name= $_POST['name'];
  5. $month=$_POST['month'];
  6. $day= $_POST['day'];
  7. $year= $_POST['year'];
  8. $time= $_POST['time'];
  9. $m= ("$month,$day");
  10. $calculate= "$month, $day, $year, $time";
  11.  
  12. ?>                     
  13.  
  14. <html>
  15. <head><style type="text/css">
  16. <!--
  17. p { color : #000000; font-family : arial narrow; font-size : medium; }
  18. h1 { color : #ff0000; font-weight : bold; font-variant : small-caps; }
  19. h2 { color : #0000ff; font-style : italic;}
  20. option, input{ color: #0000ff; font-style: bold;}
  21. .note { background-color : #ffff00; }
  22. -->
  23. </style>
  24. <title>Seconds Old Results</title>
  25. </head>
  26. <body>
  27. <form id="forml" name="form" method="post" action="results.php">
  28.  
  29.  
  30.    <fieldset>
  31.  
  32.    <legend>Form Data</legend>
  33.  
  34.    <p>
  35.  
  36.    <label for="Name"> Name :</label>
  37.    <input type="text" name="name" size="25" />
  38.    <label for="month"> Birthday :</label>
  39.    <select name="month"><option>jan</option> <option>feb</option> <option>mar</option> <option>apr</option> <option>may</option> <option>jun</option> <option>jul</option> <option>aug</option> <option>sep</option> <option>oct</option> <option>nov</option> <option>dec</option></select>  
  40.    <label for="day"></label>
  41.    <select name="day"/><option>1</option>
  42.    <option>2</option> <option>3</option><option>4</option>
  43.    <option>5</option> <option>6</option> <option>7</option> <option>8</option
  44.    <option>9</option> <option>10</option> <option>11</option> <option>12</option>
  45.    <option>13</option> <option>14</option> <option>15</option> <option>16</option>
  46.    <option>17</option> <option>18</option> <option>19</option> <option>20</option>
  47.    <option>21</option> <option>22</option> <option>23</option> <option>24</option>
  48.    <option>25</option> <option>26</option> <option>27</option> <option>28</option>
  49.    <option>29</option> <option>30</option> <option>31</option> </select>
  50.    <select name="year"><option>1980</option>
  51.    <option>1981</option> <option>1982</option> <option>1983</option>
  52.    <option>1984</option> <option>1985</option> <option>1986</option>
  53.    <option>1987</option> <option>1988</option> <option>1989</option>
  54.    <option>1990</option> <option>1991</option> <option>1992</option>
  55.    <option>1993</option> <option>1994</option> <option>1995</option>
  56.    <option>1996</option> <option>1997</option> <option>1998</option>
  57.    <option>1999</option> <option>2000</option> <option>2001</option>
  58.    <option>2002</option> <option>2003</option> <option>2004</option>
  59.    <option>2005</option> <option>2006</option> <option>2007</option>
  60.    <option>2008</option></select>
  61.    <label for="time"> Time:</label>
  62.    <select name="time"><option>01:00</option> <option>02:00</option>
  63.    <option>03:00</option> <option>04:00</option> <option>05:00</option>
  64.    <option>06:00</option> <option>07:00</option> <option>08:00</option> 
  65.    <option>09:00</option> <option>10:00</option> <option>11:00</option>
  66.    <option>12:00</option> <option>13:00</option> <option>14:00</option>
  67.    <option>15:00</option> <option>16:00</option> <option>17:00</option>
  68.    <option>18:00</option> <option>19:00</option> <option>20:00</option>
  69.    <option>21:00</option> <option>22:00</option> <option>23:00</option>
  70.    <option>24:00</option></select>
  71.    <label>CST</label>
  72.    <input type="submit" name="Submit" value="Calculate" />
  73.    <input type="reset" name="reset" value="reset" />
  74.  
  75.    </p>
  76.  
  77.    </fieldset>
  78.  
  79. </form>
  80.  
  81.    <fieldset>
  82.  
  83.    <legend>Seconds Old</legend>
  84.  
  85.    <p>
  86.    <h2>
  87.    <span class="note">
  88.    <?php
  89.    echo("Hello, $name ! ");
  90.    echo("You were born on $month $day, $year at $time o'clock".'</br>');
  91.    echo('you are ');
  92.    echo time() - strtotime("$year-$month-$day $time");
  93.    echo (' seconds old!');
  94.  
  95.  
  96.    ?>                    
  97.    </span>
  98.    </h2>
  99.    </p>
  100.  
  101.    </fieldset>
  102.  
  103. </body>
  104. </html>
  105.  
Aug 23 '07 #5
Atli
5,058 Expert 4TB
Hi.

Have you considered calculating the seconds manually, instead of using the strtotime() function?

Edit: on second thought, thats the long way around. Your way is better :)
Aug 23 '07 #6
pbmods
5,821 Expert 4TB
Heya, Wadro.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Aug 23 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Graham | last post by:
I have a variable which can be in the format "mm:ss" or "hh:mm:ss". I would like to extract the total number of seconds from this. Ie "01:30" would be 90 seconds. Thanks in advance !
3
by: nriesch | last post by:
In the documentation, the "Second" property of class DateTime is a value between 0 and 59. In UTC time, approximately every year of so, a leap second is added at 00:00:00 UTC, so as to account...
5
by: Nikeman | last post by:
good day, I simply would like to know as to how I can parse seconds to convert them into equivalent DateTime representation. To be more persice, I have a DirectShow app written in VB.NET, with a...
4
by: Dr John Stockton | last post by:
I'm starting a new thread, for clarity. I'm assuming that it's ECMA-262 3rd Edn (1999) that we should be using for Web pages; that 4th Edn (what's its present status? is it available?) is too...
5
by: charlie strauss | last post by:
Below is a simple program that will cause python to intermittently stop executing for a few seconds. it's 100% reproducible on my machine. I'd be tempted to say this is a nasty garbage...
19
by: edfialk | last post by:
Hi, does anyone happen to know of a script that would return the number of seconds in a month if I give it a month and a year? My python is a little weak, but if anyone could offer some...
37
by: David T. Ashley | last post by:
I have Red Hat Enterprise Linux 4. I was just reading up about UTC and leap seconds. Is it true on my system that the Unix time may skip up or down by one second at midnight when there is a...
5
by: =?Utf-8?B?U2hlbGRvbg==?= | last post by:
Hello - I have about ten integer values that each need to be converted to days, hours, minutes and seconds. I can't seem to find a formula for same that works. These integer values come from a...
3
by: =?Utf-8?B?U2hlbGRvbg==?= | last post by:
Hello - I have various times formatted like 00:00:00, so for example, 01:32:05 would be one thirty-two with five milliseconds. I need to convert this into seconds (an integer). First of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.