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

DateTime Picker

153 100+
Hi all,

I ve discovered the power of php/mysql/html in last few days whilst putting together an online app to enable the staff of a friends company to log on and enter their current location and time due to leave current location.

So far so good, they can select their name from a drop down box, enter location and time leaving which is then stored in a database to be loaded in another page.

Now, one of the requests of my friend was to have the ability to scan the page and see if anyone is overdue - current time vs time leaving.

So I have tried and thought of many different approaches to acheive what i was once acheived with datediff - vb but can't seem to find a solution. If only it was as easy as currentTime - timeLeaving . But it's not.

I know javascript has something similar to datediff but can you acheive tis with php?

Any directions would make my life easier??!!

B
Jan 21 '09 #1
4 5828
pbmods
5,821 Expert 4TB
Heya, Brendan.

To calculate the difference between two dates, convert them into timestamps using the strtotime() function (PHP: strtotime - Manual), then subtract them. The result will be the number of seconds between the dates.

E.g.,:
Expand|Select|Wrap|Line Numbers
  1. $date1 = '2009-01-21';
  2. $date2 = '2009-02-01';
  3.  
  4. $secondsBetweenDate1AndDate2 = strtotime($date2) - strtotime($date1);
  5.  
  6. /* 86400 seconds in a day, so divide by that to get the # of days. */
  7. $daysBetweenDate1AndDate2 = (int) ($secondsBetweenDate1AndDate2 / 86400);
  8.  
Jan 22 '09 #2
brendanmcdonagh
153 100+
Hi there

The problem with the above solution is having to get the user to manually insert datat and time in html form, very unpredictable. I can have a now() function to insert current timestamp in an mysql field, in fact I have done that.

But, I have got to get the time and date of when the user is due to leave current location in a Time Leaving: <input type="text" name="time"> with html.

The best I can hope for is getting them to enter 22:05 but then this isn't compatible with my datadiff hopes. I 've tried. I know now it's going to have to be timestamp in mysql and timestamp in html/php but to get them to enter manually in the format needed is out of the question. That's why a date/time picker is needed.

So my work/question now involves:

How can i get a date/time picker - such as a drop down box for year, month, day, hh, mm.

Then i'm in a better position to work with the timestamp from mysql - (now() and the date/time entered by the user to find the difference.
Jan 22 '09 #3
brendanmcdonagh
153 100+
Hi again,

I have decided to try the following:

have a table in my database for each of the following:

day, month, h, mm

then im showing these values in seperate drop down boxes on my page and posting inputs to insert2.php

the following is working

Expand|Select|Wrap|Line Numbers
  1. $day = $_POST['day'];
  2. $month = $_POST['month'];
  3. $hour = $_POST['hour'];
  4. $minutes = $_POST['minutes'];
  5. $alltogether = $day . " " . $month . " " . $hour . ":" . $minutes . " ";

my output being 27 January 16:30

As im asking I m thinking it's a long shot but is there any way to compare this with current time to determine if &alltogether is past current time?
Jan 22 '09 #4
Atli
5,058 Expert 4TB
Hi.

Consider using <select> boxes for the date/time input.
Your user would simply be presented with a drop-down box for the year, month and day, and either a drop-down for the time to or simply a text input for the time.
Expand|Select|Wrap|Line Numbers
  1. <select name="date_year">
  2.   <option value="2009">2009</option>
  3.   <option value="2010">2010</option>
  4.   <!-- etc... -->
  5. </select>
  6. <select name="date_month">
  7.   <option value="01">January</option>
  8.   <option value="02">February</option>
  9.   <!-- etc... -->
  10. </select>
  11. <!-- etc... -->
That way you would be able to assume a fairly accurate date input from your users.

And to get the "overdue" times, if you have all the dates in your database in DATE, DATETIME or TIMESTAMP columns, you could have a SQL query fetch all the overdue rows. For example:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM myTable
  2. WHERE timeToLeave < NOW();
Which should return only rows where the "timeToLeave" value is in the past.
Jan 22 '09 #5

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

Similar topics

1
by: Colin Joss | last post by:
Sorry folks, being a bit dense here. I need a DateTime Picker for a PDA application I'm building. Couldn't see one in the standard tools so search Microsoft. Found one. Downloaded it. Now...
0
by: Ata İsmet Özçelik | last post by:
Hi there, I have a problem with the DateTime picker.. I want to use my custom format; for this I can give a string for the format.But My goal is to have the month name in the box in upper case...
1
by: Dean L. Howen | last post by:
Dear friends, Could you help me to solve the problem: How can we set/get NULL values of datetime in DatetimePicker ? I design a form using DateTimePicker to input/output date value, but the date...
0
by: Qumer Mumtaz Goraya | last post by:
Hi There is a datatime picker control in one column of my datagrid.When the cell of sepecific column get the focus the datetime picker control appeare It shows the current system date.If once I...
3
by: Brian | last post by:
Hello, I have a wierd problem. I have a datetime picker that doesn't seem to want to sinc up its .value and .text proberties. I can step through the code and see that they are different values. ...
5
by: Michel Posseth [MCP] | last post by:
Hello we have encountered the following problems with the date time picker control A : datetime picker control gives focus to last entered field when moving back and forward with focus how do...
1
mafaisal
by: mafaisal | last post by:
Hello Experts I am Using vb.net 2005 Hw To Put DateTime Picker in Datagrid view I have to sea Datetime Picker in Specified Cilomn of Datagrid I try This But The Location Hw To Change to the...
4
by: gggram2000 | last post by:
Hi, I'm using php 5.2.3 with mysql server 5.1 as backend. I have a program in which a person enters or chooses two dates from two datetime pickers and other info, I'm not sure if the problem is...
1
by: sonubaba | last post by:
hello, my question is, in my web application i need datetime picker control in which user can select both date and time from DateTime Picker control i could not find this anywhere on inter net ...
0
by: =?Utf-8?B?a3BpenpsZQ==?= | last post by:
Hi all. using vs.net 9, C# I've got a trivial dilemma right now with my datetimepicker. It is bound to a datetime field in a database. This field is also set to not allow nulls. The default...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.