Solved

php: midnight

Posted on 2004-08-06
11
2,001 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
Comment Utility
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
Comment Utility
Here is a link that describes cron jobs pretty well:

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

Author Comment

by:imaw
Comment Utility
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
 
LVL 25

Expert Comment

by:Squinky
Comment Utility
Create a time value that represents today at midnight:

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

Expert Comment

by:dubrie
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:imaw
Comment Utility
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
Comment Utility
To make midnight just do what he said:

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

Expert Comment

by:Squinky
Comment Utility
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
Comment Utility
where before all my code stated above?
it didn't work. that's why i need visual example.
0
 
LVL 25

Accepted Solution

by:
Squinky earned 500 total points
Comment Utility
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
Comment Utility
Thanks.
as simple as that. that's all i neeeded.
it works perfect.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 count occurrences of each item in an array.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now