Insert Java Script Date in PHP Echo Statement - TechRepublic
Question
January 8, 2007 at 06:10 AM
twanstall

Insert Java Script Date in PHP Echo Statement

by twanstall . Updated 19 years, 5 months ago

Hi all,

i was hoping for some technical help using php and mysql.

I have a simple database connected (mysql) and website (php/html).

A form of this website involves me inputting a date field in it. i have created a date function using the following javascript code:

var todaysdate = new Date();
year = todaysdate.getFullYear();
month = todaysdate.getMonth();
date = todaysdate.getDate();
day = todaysdate.getDay();

var monthname = new Array(“01″,”02″,”03″,”04″,”05″,”06″,”07″,”08″,”09″,”10″,”11″,”12”);
var dayname = new Array(“Sunday”,”Monday”,”Tuesday”,”Wednesday”,”Thursday”,”Friday”,”Saturday”);

The date is inserted into the webpage using the following code:

.

Basically i want to be able to insert this javascript date (by default) into the date field of my form, using the php echo method, if it is possible????

Example:
document.writeln(year+”-“+monthname[month]+”-“+date); ?>

Please help as this is doing my head in!!!!!

Thank You

tom

This discussion is locked

All Comments