Solved

php: midnight

Posted on 2004-08-06
11
2,013 Views
Last Modified: 2008-02-26
I need to normalize my local time to midnight? How can I do so?
I would like to be able to choose today date.
here is my code:
*****************
 $T1date = strtotime($T1);
     $localtime = time();
     $localdate =  date('m/d/Y',$localtime);

          if($localtime > $T1date)
            {
             $validate = false;
             $error = 2;
            }
             $today = getdate();
             $month = $today['month'];
             $mday = $today['mday'];
             $year = $today['year'];
0
Comment
Question by:imaw
  • 4
  • 4
  • 3
11 Comments
 

Expert Comment

by:dubrie
ID: 11738545
You would probably have to do this in a cron job and have it set to run at midnight.  Cron jobs are somewhat readily available from hosting companies.
0
 

Expert Comment

by:dubrie
ID: 11738574
Here is a link that describes cron jobs pretty well:

http://www.bitfolge.de/pseudocron-en.html
0
 

Author Comment

by:imaw
ID: 11738584
all i want to do is be able  to choose today but I can't because no matter what, localtime will always be later than $T1 because it contains minutes seconds etc...
I knwo this possible without the hosting company.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 11738594
Create a time value that represents today at midnight:

$localtime = strtotime('00:00');
0
 

Expert Comment

by:dubrie
ID: 11738614
Also, you can specify what to read in when you set the time/$localtime.  You can use the date() function and just grab an hour in either 12 or 24 hour format:

$12hourtime = date("h");

$24hourtime = date("H");

More specs on the date function can be found here:  http://us2.php.net/date
0
 

Author Comment

by:imaw
ID: 11738665
Is this close?
$T1date = mktime(0,0,0,$T1string[1],$T1string[2],$T1string[0]);


Squinky,
 can show an example with my code stated above?
0
 

Expert Comment

by:dubrie
ID: 11738693
To make midnight just do what he said:

$midnight = strtotime('00:00');
0
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 11738751
No idea what you're doing there!

You can normalise $T1date the same way (as it appears to be a timestamp already):

$T1date = strtotime('00:00', $T1date);

alternatively, do the comparison with strings instead:

$localdate =  date('Y-m-d', $localtime);
$t1string =   date('Y-m-d', $T1date);
if($localdate > $T1string)

Because the strings are in ISO format (YYYY-MM-DD), they can be compared correctly.
0
 

Author Comment

by:imaw
ID: 11738811
where before all my code stated above?
it didn't work. that's why i need visual example.
0
 
LVL 25

Accepted Solution

by:
Marcus Bointon earned 500 total points
ID: 11738883
I just didn't paste the bits that were the same...

$T1time = strtotime($T1);
$T1date = strtotime('00:00', $T1time)
$localdate =  strtotime('00:00');

          if($localdate > $T1date)
            {
             $validate = false;
             $error = 2;
            }
             $today = getdate();
             $month = $today['month'];
             $mday = $today['mday'];
             $year = $today['year'];

The only thing I'd say is that it's very unclear what you're actually trying to do. Although my example is syntactically ok, I couldn't tell you how useful it is logically as I don't know what you're trying to achieve.
0
 

Author Comment

by:imaw
ID: 11738943
Thanks.
as simple as that. that's all i neeeded.
it works perfect.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP error function not working on AWS 10 71
PHP breaks when used in Wordpress template file 3 31
Inserting data into database 10 36
if (is_singular not working 5 18
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

837 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