Jump to content

strtotime() problem


j.smith1981

Recommended Posts

I have a php dilemma here.

 

I have a string to time function dilemma here (that I didnt notice would happen), I have a really big search facility here, that we have had our first customer order on.

 

At the moment, you say search on one date like so:

 

From :15th of feb 2010

To: 15th of feb 2010

 

Would bring up the same time wouldnt it, missing the results in effect.

 

How would one go from midnight on the 'From' part (ie 00:00), to right at the end of the day on the To date (23:59)?

 

This would be using some form of offset wouldnt it, how would I achieve this please?

 

Any help is greatly appreciated, thanks.

 

Jeremy.

Link to comment
https://forums.phpfreaks.com/topic/192146-strtotime-problem/
Share on other sites

strtotime() will only work properly on US English date formats, for example 15 January 2009 08:41:03.

 

So you will have to expand the month to its full name, so instead of feb it will need to be February. You'll also need to loose the ordinal suffix (st, nd, rd or th) too from your original dates. With your dates now in the format strtotime expects you can do this

 

$fromDate = '15 February 2010 05:00:00';

$toDate = date('j F Y H:i:s', strtotime('+23 hours 59 minutes', strtotime($fromDate)));

echo "$fromDate to $toDate";

Link to comment
https://forums.phpfreaks.com/topic/192146-strtotime-problem/#findComment-1012710
Share on other sites

  • 3 weeks later...

Sorry to be a pain with this lol.

 

But I am having real problems in getting the output I want from your example.

 

At the moment, I have cleared out my code and gone from whats been generating from my search form, this is as below:

03 5 2010

 

Thats the same format for the from and to date yea?

 

How would I go from saying with that value, getting it to use the date from the start say 00:00 am to 23:59:59 at night? Of course being afternoon.

 

If I say it was the $fromdate and then the $todate those values where echoing out as as it where, how would I go from that whole echo to coming out with the equivalent time stamp sorry?

 

If you could give me some more help I would greatly appreciate it!

 

Regards,

Jeremy.

Link to comment
https://forums.phpfreaks.com/topic/192146-strtotime-problem/#findComment-1021890
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.