0

I am new to PHP and cannot figure out the best method to convert two strings I have from URL params.

I would like to convert: "August 2010" to ---> "2010-08-%"

and also: "2010" to ---> "2010-%-%"

Thank you in advance!

2 Answers 2

4

You can use the strtotime function with date:

echo date('Y-m', strtotime('August 2010'));

Just adjust the format parameter to the date function to get the result in the format you are looking for. You might want to append the % part after convert the date format.

Sign up to request clarification or add additional context in comments.

1 Comment

ah thank yee, i knew i was doing something wrong. previously i used looping and the explode function to piece the string together!
2

You can do those by learn to using these 2 following functions
strtotime http://php.net/manual/en/function.strtotime.php
date http://php.net/manual/en/function.date.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.