Using strftime

The time has been set to January 31, 2011

Using strftime(): The date today is 01/31/11

Getting rid of leading zeros

Step 1: Mark the elements with leading zeros: The date today is *01/*31/11
Step 2: Use a custom function to remove the leading zeros

  1. Pass the strftime() function as the parameter
  2. Use str_replace to replace any zeros with an asterisk with an empty string
  3. Use str_replace to replace any remaining asterisks with empty strings
  4. Return the final result
    This can be simplified to the following: str_replace('*', '', str_replace('*0', '', '$marked_string))
Step 3: Echo out the result: The date today is 1/31/11

Using MySql format

Use the following format: strftime("%Y-%m-%d %H:%M:%S", time()): 2012-05-17 15:19:01