theknight;10987808 wrote:Resolved it, formatting issue.
All dates have to be formatted this way:
month day Year
Otherwise it does not produce the correct timestamp
Wrong! All dates have to be formatted in any of the ways described acceptable by the manual. There is a link to the page of acceptable formats on the strtotime page.
theknight;10987807 wrote:
Its the format outputted by MSSQL
Don't they have the DATE_FORMAT function?
theknight;10987807 wrote:
The actual time stamp is not similar when I tried this.
Similar to what? PHP's time functions do not randomly return some integer > 0. What use would a time function be if it produced varying times for the same given input?
echo strtotime('2011-10-16 12:00AM') . '<br/>';
echo strtotime('2011-10-16') . '<br/>';
echo strtotime('10/16/2011 12:00AM') . '<br/>';
echo mktime(0, 0, 0, 10, 16, 2011) . '<br/>';
output
1318716000
1318716000
1318716000
1318716000
That is, they are all not just similar, but identical.
theknight;10987806 wrote:
This worked but the outputted timestamps are not accurate.
Yes, they are.
theknight;10987806 wrote:
$date = date("Y m d");
echo mktime($date).'<br>';
$text = "2011 09 15 12:00AM";
$bang=explode(' ',$text);
echo mktime(0,0,0,$bang[2],$bang[1],$bang[0]);
//outputs 1331251200
Time stamps are different.
Of course they are. You don't create them using the same input. The first one has input 2011, which I wouldn't know where to being to guess how it's treated for hour value, since hour has range 0-23, which makes this
echo mktime(2011);
very weird indeed.
theknight;10987806 wrote:
when the first timestamp is todays date and therefore should be more accurate.
More accurate than what? They are all equally accurate.
theknight;10987806 wrote:
Turns out timestamps are not similar to the dates.
Dates specify a specific day while a timestamp specifies a specific time. If you convert a date to a timestamp, you are (by convention) taking the midnight time, 00:00:00, of that day and turning that into a timestamp.
As for your little mktime example, you do have to actually follow the format of the input parameters of the functions you use
/*
# todays date 15/09/2011
$date = date("Y m d");
echo $date.'<br>';
echo mktime($date).'<br>';
*/
echo (int) '2011 09 15';
echo '<br/>';
echo mktime('2011 09 15') . '<br/>';
echo mktime(2011);
Output (at 2011-09-15 15:16:31)
1316092591
1316092591
which is, once again, entirely accurate and produces identical output to equivalent input parameters.