LittleNicky Posted August 8, 2006 Share Posted August 8, 2006 How do I set the date & time (in one field) automatically as the current date & time when I'm inserting into a field? Also what should I have the field set as in the mySQL database? Link to comment Share on other sites More sharing options...
aspnetguy Posted August 8, 2006 Share Posted August 8, 2006 read thishttp://ca.php.net/dateas for the mysql field make sure you use the one of these datatypes DATE YYYY-MM-DD.DATETIME YYYY-MM-DD HH:MM:SS. Link to comment Share on other sites More sharing options...
morrisjohnny Posted August 10, 2006 Share Posted August 10, 2006 Hi i was just reading and i decided it would be nice to put it on my site, anyway of course a few problems arised it said my time was 11:00am when its 7:00pm, anyway i was wondeirng is their anyway that you can make it read from the users pc clock?Also this is not as imporant but can u make it automatcially refresh after 1 minute?Thanks-Jny Mrs Link to comment Share on other sites More sharing options...
aspnetguy Posted August 10, 2006 Share Posted August 10, 2006 you need javascript to get the clients pc time.use this <html><head> <title>JavaScript Date and Time</title> <script type="text/javascript"> function writeDateTime() { var dateo = new Date(); var th = document.getElementById('timeHolder'); th.innerHTML = getDateNow(dateo) + " " + getTimeNow(dateo); setTimeout(writeDateTime,1000); } function getDateNow(dateo) { return dateo.getDay() + "/" + dateo.getMonth() + "/" + dateo.getYear(); } function getTimeNow(dateo) { var hr = dateo.getHours(); var min = dateo.getMinutes(); var sec = dateo.getSeconds(); if(hr > 12) hr = hr - 12; if(min < 10) min = "0" + min; if(sec < 10) sec = "0" + sec; return hr + ":" + min + "." + sec; } </script></head><body> <div id="timeHolder"></div> <script> writeDateTime(); </script></body></html> Link to comment Share on other sites More sharing options...
skym Posted August 10, 2006 Share Posted August 10, 2006 Use java script: http://www.w3schools.com/jsref/jsref_obj_date.asp (like aspnetguy just said before me).I have some code to show the date, day and clock, updates each second: <script type="text/javascript"><!--//var myMonths=new Array("January","February","March","April","May","June","July","August","September","October","November","December");var myDays= new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");today=new Date();thisDay=myDays[today.getDay()];thisMonth=myMonths[today.getMonth()];thisYear=today.getFullYear();thisDate=today.getDate();todaysDate=thisDay+", "+thisDate+" "+thisMonth+" "+thisYear;function myClock(){today=new Date();var theHours=today.getHours();if (theHours>11){theTimeSuffix="PM";}if (theHours>12)var theHours=theHours-12;else{theTimeSuffix="AM";}var theMinutes=today.getMinutes();if (theMinutes<10)var theMinutes="0"+theMinutes;var theSeconds=today.getSeconds();if (theSeconds<10)var theSeconds="0"+theSeconds;var theTimeNow=theHours+":"+theMinutes+":"+theSeconds+" "+theTimeSuffix;//document.formTime.textTime.value=theTimeNow;document.getElementById('time').innerHTML=theTimeNow;}var clockWork=setInterval("myClock()",1000);//--></script><script type="text/javascript"><!--document.write(todaysDate);//--></script>- <span id="time"></span> Link to comment Share on other sites More sharing options...
aspnetguy Posted August 10, 2006 Share Posted August 10, 2006 so does the script I posted...it just doesn't write out the day or month but prints them as numbers Link to comment Share on other sites More sharing options...
skym Posted August 11, 2006 Share Posted August 11, 2006 Hmm, sorry! I didn't see the setTimeout(), I saw your post when previewing my response for the topic. Link to comment Share on other sites More sharing options...
morrisjohnny Posted August 14, 2006 Share Posted August 14, 2006 Thanks VM i have got it to work Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now