Page 1 of 1

Help with mktime()

Posted: Sun Apr 27, 2003 3:26 pm
by werlop
Hi, I need to convert some dates into timestamps, I am using the mktime() funtion.

The code I have tried is as follows:

Code: Select all

<?php
$timestamp = date ("U", mktime( 0,0,0,$_POST[month],$_POST[daynumber],$_POST[year]) );
?>
At first this seemed to work, but on closer inspection it does not work as expected.

If I run the code below after making $timestamp I get

27May2003
1040947200
27 Fri December 2002
30 Sat November 2002

Code: Select all

<?php
	print $_POST[daynumber];
	print $_POST[month];
	print $_POST[year];
	print "<br>";
	print $timestamp;
	print date( " d D F Y", $timestamp );
	print date( " d D F Y ", mktime ( 0,0,0,date("D"),date("F"),date("Y")));
?>
This prints the data used to make the timestamp, then the timestamp itself, then uses the date function to make the date using the timestamp (an error occurs here, the 2 dates don't match) It then prints the current date using the mktime() function, and yet again an error occurs here. Does anybody know what's wrong with this?

If not, could you please explain to me how to get the ordinal suffix for a certain number (eg for 1 it would be st, for 2 it would be nd and for 3 it would be rd, etc) without using a timestamp?

Thanks for any help

David

Posted: Sun Apr 27, 2003 6:22 pm
by patrikG
Have a look at http://www.php.net/manual/en/function.strtotime.php and see if that's what you're looking for.

Posted: Mon Apr 28, 2003 2:03 am
by twigletmac
And (although off-topic) also please read:
http://www.php.net/manual/en/language.t ... rray.donts
and start putting quotes around your element names.

Mac

Posted: Mon Apr 28, 2003 3:51 am
by Mr. Tech
I just use this:

$newtime = strtotime(28th April 2003);

:D

Posted: Mon Apr 28, 2003 2:26 pm
by werlop
Thanks this worked perfectly :D I looked at the manual but for some reason I couldn't find what I wanted (probably lack of coffee).

Also thanks for the bit about arrays!

David