Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a Javascript Date format to desired PHP format

Tags:

javascript

php

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

like image 427
Aadi Avatar asked Jun 09 '10 12:06

Aadi


People also ask

How convert date format from DD-MM-YYYY to Yyyymmdd in PHP?

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: ".

How can get date in dd-mm-yyyy format in PHP?

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: " .

What date format is DD MMM YYYY JavaScript?

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.

How to convert JavaScript date to PHP code?

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.

How to convert datetime to any custom format in JavaScript?

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.

What are the different date input formats in JavaScript?

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.

What does the date_format() function return?

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.


1 Answers

<?php
$jsDateTS = strtotime($jsDate);
if ($jsDateTS !== false) 
 date('Y-m-d', $jsDateTS );
else
 // .. date format invalid
like image 142
MANCHUCK Avatar answered Sep 23 '22 05:09

MANCHUCK