Forum Moderators: coopster

Message Too Old, No Replies

Timestamp

php timestamp

         

scriptmasterdel

3:12 pm on Mar 24, 2006 (gmt 0)

10+ Year Member



Hello All,

Does anyone know how to convert a date into a timestamp?

This would help me alot, i want to convert something like "18061986" (18th june 1986) into a timestamp format, but i don't understand the conversion process.

Please help.
Thanks in advanced,
Del

RonPK

3:40 pm on Mar 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is a function strtotime() [php.net] that handles certain input formats. You'll probably be better of with mktime:

mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year]]]]]]);

In your case, use substr() to get the relevant pieces from your string:

$timestamp = mktime(
0,
0,
0,
substr($mydate, 2, 2),
substr($mydate, 0, 2),
substr($mydate, 4)
);

Please note that using a timestamp to represent a date is a bit silly ;)

scriptmasterdel

4:01 pm on Mar 24, 2006 (gmt 0)

10+ Year Member



I'm actually creating a caledar for a website and the only way i can see to retrive the day of the month is using the getdate() function and to use that i need to pass a timestamp.

Confusing way of doing it? Please let me know if i can do this easier.

Many thanks!

HoagieKat

4:14 pm on Mar 24, 2006 (gmt 0)

10+ Year Member



the current day of the month is got by:

$day=date("d");