How to Convert a Date to a UNIX Timestamp PHP

The UNIX Timestamp is the time in seconds between January 1, 1970, and any date. The PHP "strtotime" function can be used to convert a date specified as a string into the UNIX Timestamp for that date. The date can be specified within the "strtotime" function, or it can be passed to the function as a variable. The string can be written as "01 January, 2010" or as "next Thursday," "+1 week" or "now."

Instructions

    • 1

      Open a blank text document in any text editor.

    • 2

      Type "<?php" to begin the PHP script.

    • 3

      Type "echo date('d F\, Y')."\n";" to print out the current date in the format "01 January, 2010."

    • 4

      Type "$convert= date('d F Y');" to place the current date into the "$convert" variable.

    • 5

      Type "echo strtotime($convert)."\n";" to print the UNIX Timestamp for the current date.

    • 6

      Type "?>" to close the PHP script.

    • 7

      Save the script with the ".php" file extension.

    • 8

      Execute the script by typing "php script.php" from the command line.

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured