I am facing a problem that whenever I try to store date in parse it gives me this error 'invalid type for key expires_on, expected date, but got string'. How can I convert string object to date object? The format of date '21 April 2015 - 10:50' and the data type of column field in Parse DB is date.
Asked
Active
Viewed 563 times
1 Answers
1
You can use DateTime
function of PHP to store data if your getting it into string.
$input_date = $_REQUEST['expireDate'];
$date = DateTime::createFromFormat('d F Y - H:i',$input_date);
$expireDate = $date->format('Y-m-d');
echo $expireDate;
The above code will convert your string into date that will be used to store data

Narendrasingh Sisodia
- 21,247
- 6
- 47
- 54
-
Thanks for your reply. But it is not working, still it gives me string datatype. – Subzz Apr 07 '15 at 07:29
-
What you are getting within string can you update your question. What I have done over here is I have converted your `'21 April 2015 - 10:50' ` as date. I thought you might be getting your values within this format in string – Narendrasingh Sisodia Apr 07 '15 at 07:30
-
Well i actually get date from calendar and submit it through form, then i get that value of input field from $_REQUEST. so after that when i store that value in table then it gives me error. – Subzz Apr 07 '15 at 07:35
-
Thats because you are getting string value and storing directly into your `db` Have you tried the above code – Narendrasingh Sisodia Apr 07 '15 at 07:36
-
yes i have tried your code, infact i simple copy paste that code with static date value, but when i get the type from gettype function it is also giving me string type. – Subzz Apr 07 '15 at 07:37
-
Can you please update your question what you were getting within `$_REQUEST[]` – Narendrasingh Sisodia Apr 07 '15 at 07:39
-
$expireDate= $_REQUEST['expireDate']; i am getting date from input field like this and then i want to store $expireDate variable in database. – Subzz Apr 07 '15 at 08:21
-
@Subzz I have updated answer you can check it.. – Narendrasingh Sisodia Apr 07 '15 at 08:32
-
Thanks Man. but is not working :( actually when you use gettype($expireDate) function to get the datatype of $expireDate it gives me string instead of date.. Thats my point. – Subzz Apr 07 '15 at 08:58
-
But you can store that value within database are you getting any error within it while storing within database – Narendrasingh Sisodia Apr 07 '15 at 09:02