SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Date and Time in Form

    How would I create a hidden field that grabs the date and time that a user registered?

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does your server support PHP?

    -Sam
    Sam Hastings

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes it does. The form is currently static, though and if possible would like it to stay that way.

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All you need to do is change the page extension to .php and update your links if necessary, then you can add this. I would recommend it.

    PHP Code:
    <?php
    $regdate 
    date("j F, Y");
    ?>
    <input type=hidden name=date value="<? echo $regdate?>">
    Then the date will be passed as a variable named 'date' to the form handler.

    It's a lot easier than using JavaScript, try it!

    -Sam
    Sam Hastings

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you!
    is there a way to do it with javascript though

  6. #6
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's a quickie little custom date object I just wrote....should do pretty much anyting you need.
    Code:
    <html>
    <head>
    <title>Date test</title>
    
    <script>
    
    function myDate() {
    	var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
    	var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
    	var d = new Date("May 1, 1999 00:30:15");
    	this.epoch = d.getTime();
    	this.year2 = d.getYear();
    	this.year4 = d.getFullYear();
    	this.leap = (this.year4 % 400 == 0) ? true : (this.year4 % 4 == 0 && this.year4 % 100 != 0) ? true : false;
    	this.mnth = d.getMonth();
    	this.month = this.mnth + 1;
    	this.monthName = months[this.mnth];
    	this.dy = d.getDay();
    	this.day = this.dy + 1;
    	this.dayName = days[this.dy];
    	this.date = d.getDate();
    	this.hours24 = d.getHours();
    	this.hours12 = (this.hours24 == 0) ? 12 : (this.hours24 > 12) ? this.hours24-12 : this.hours24;
    	this.minutes = d.getMinutes();
    	this.seconds = d.getSeconds();
    	this.ampm = (this.hours24 == 0) ? "am" : (this.hours24 >= 12) ? "pm" : "am";
    	this.GMTstring = d.toGMTString();
    	this.offset = d.getTimezoneOffset();
    	}
    
    </script>
    
    </head>
    <body>
    <pre>
    <script>
    var today = new myDate();
    document.write("<b>Property\tValue</b><br>-----------------------------------<br>");
    for (var i in today) {
    	var tabstops = (i.length < 8) ? "\t\t" : "\t";
    	document.write(i + tabstops + today[i] + "<br>");
    	}
    </script>
    </pre>
    </body>
    </html>
    Last edited by beetle; Nov 18, 2002 at 16:37.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank You!

    Army of Darkness - always good!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •