How can we convert Wed Jun 09 2010 which is returns from a javascript function and get in a php script.I need to convert this date format to 2010-06-09.Thanks
Change DD-MM-YYYY to YYYY-MM-DD In the below example, we have date 17-07-2012 in DD-MM-YYYY format, and we will convert this to 2012-07-17 (YYYY-MM-DD) format. $orgDate = "17-07-2012"; $newDate = date("Y-m-d", strtotime($orgDate)); echo "New date format is: ".
php /*print date in dd/mm/yy format*/ print "Current date in dd/mm/yy format: " . date("d/m/y"); print "</br>"; /*print date in dd/mm/yyyy format*/ print "Current date in dd/mm/yyyy format: " . date("d/m/Y"); print "</br>"; /*print date in dd MON yyyy format*/ print "Current date in dd MON yyyy format: " .
There is no native format in JavaScript for” dd-mmm-yyyy”. To get the date format “dd-mmm-yyyy”, we are going to use regular expression in JavaScript. The regular expression in JavaScript is used to find the pattern in a string.
This way you have less problems with timezones. You can use this javascript function to convert the dateObject or date string to your desired format: Then you can pass this formatted date to your PHP code where you can use function strtotime to convert this date to your desired format.
Php has a date_format () function which can convert the datetime into any custom format. But sadly javascript do not have any such thing. So, we have implemented one for it. Although, there are many wonderful libraries like moment.js to deal with datetime but sometimes we just want simple and lightweight solution.
JavaScript Date Input. There are generally 3 types of JavaScript date input formats: The ISO format follows a strict standard in JavaScript. The other formats are not so well defined and might be browser specific.
The date_format () function returns a date formatted according to the specified format. Note: This function does not use locales (all output is in English). Tip: Also look at the date () function, which formats a local date/time. Required. Specifies a DateTime object returned by date_create () Required. Specifies the format for the date.
<?php
$jsDateTS = strtotime($jsDate);
if ($jsDateTS !== false)
date('Y-m-d', $jsDateTS );
else
// .. date format invalid
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With