php date

  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

how do i submit a date on a form into a database without the user fillin in the date? i also want to use the date sent to the databe to also be part of the autoresponder that i have already setup

using this somewhere would be great:
PHP Code: [ Select ]
 
<?php
 
echo strftime( '%Hh %M %A %d %b', time() );
 
?>
 
 
  1.  
  2. <?php
  3.  
  4. echo strftime( '%Hh %M %A %d %b', time() );
  5.  
  6. ?>
  7.  
  8.  
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

why not try:

$date = NOW();

then in your query add, 'NOW()' on the values bit...
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

what format will the $date be shown in? i read where it will be just a integer. just showing numbers rather than in traditional date format
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

To get today's date:

http://uk2.php.net/manual/en/function.time.php

Save the timestamp (number of seconds from 1st jan 1970) into the databse as an integer value.

Then when you want to output the date, run it through:

http://uk2.php.net/manual/en/function.getdate.php

Which gives nice formatting to the timestamp. Having never used these functions I just did a little test script:

PHP Code: [ Select ]
<?php
 
$timeNow = time();
 
echo("the current timestamp = <b>$timeNow</b> <-- this is what gets saved in the database");
 
 
 
 
 
$dateArray = getdate($timeNow);
 
 
 
echo('<hr>Then you get ^that^ value back from the database, and format it using getdate() <pre>$dateArray = ');
 
print_r($dateArray);
 
echo('</pre>');
 
?>
  1. <?php
  2.  
  3. $timeNow = time();
  4.  
  5. echo("the current timestamp = <b>$timeNow</b> <-- this is what gets saved in the database");
  6.  
  7.  
  8.  
  9.  
  10.  
  11. $dateArray = getdate($timeNow);
  12.  
  13.  
  14.  
  15. echo('<hr>Then you get ^that^ value back from the database, and format it using getdate() <pre>$dateArray = ');
  16.  
  17. print_r($dateArray);
  18.  
  19. echo('</pre>');
  20.  
  21. ?>


which outputs this

//edit: this is almost exactly what axe said in [url=http://www.ozzu.com/programming-forum/date-time-sql-t27652.html[/url]this thread[/url] on the second post. The date() function looks more customisable in it's output, but getdate() looks easier to use, so it's up to you, depending on how you want to display the date.

//edit (again): As far as I am aware all databases store dates as numeric times from a given (standard to that dbms) date. It's the best way of storing the information, as it is easier to manipulate, reformat, do calculations with etc.
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

what i want to do really is have the date stored in a database then pull it out of the database when i do an autoresponder. i already have a lil personalisation. it starts like this:
PHP Code: [ Select ]
 
'Hello '.$_POST['name'].', thank you for filling out the form '
  1.  
  2. 'Hello '.$_POST['name'].', thank you for filling out the form '
i would like to pull the date out in a similar way. i want to display the date in a yyy-mm-dd format so it dsiplays as 2004-12-29 with the name of the person, address, number and so on and so on. etc.
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

so you use date() like axe said and format it however you like. You really don't want to be storing it as a string. You want to store it as an integer, trust me, it's much more useful :D

So when you pull the integer timestamp out of the database you can run it through:

PHP Code: [ Select ]
echo(date("Y - m - d",$timeOfFormSubmission));


Check out the manual (RTFM) for the date() function, it's really quite simple now I look at it and darn handy: http://uk.php.net/date

Actually, hang on. If you are using post['name'], what is the database getting used for :?

Either way, generate the timestamp and only format it into a date when you want to display it, for manipulation calculation and storage it is best to keep it as an integer
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

Code: [ Select ]
<input type="text" name="my_date" value="<? echo strftime( '%H:%M %a %d %b %G', time() );?>" READONLY>


the out put is this: '16:42 Thu 15 Jul 2004' now can i (using the name attribute) actually read this into the databse and pull it out in the same way or is this purely for display purposes and not to be mixed with a mysql database?
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

the date is purely used as a timestamp for when the form was submited. i want to use it in the autoresponder. values like $_post['name'] are pulled out from the database only for the autoresponder (for now).

when you say that storing the date as an integer is much more useful, what do you mean? for my purposes can i store it as a string because no complicated queries or commands will be used on this at all. its purely for display purposes
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

the reason why the strftime appealed to me was because i could call it from the database. how do i call the timestamp from the database. how is it represented. $timestamp is then put into the database in what way. i need the time of when the form was filled out / submitted so i can get the time and put it on the autoresponder. so far the auto responder contains values like $_post['name']
PHP Code: [ Select ]
'Hello '.$_POST['name'].', thank you for filling out the form '
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

buzzby365 wrote:
when you say that storing the date as an integer is much more useful, what do you mean? for my purposes can i store it as a string because no complicated queries or commands will be used on this at all. its purely for display purposes
Well there is extensibility. If you are storing info in a database it is being kept for future reference, right? Therefore in the future you may decide it looks better to display with a long date at some point in the future and then the data in the database gets out of date. This will not happen if you use a <b>standardised</b> date format. Plus you can see how long ago the form was submitted (using simple subtraction). Or you can clear out any forms with dates more than 30 days old et cetera ad nauseum.

Anyway it makes no difference how you store it in the database. If you store the timestamp you will need to use an integer, if you store it formatted it will need to be stored as a string. Any formatting function returns a string, there is nothing special about it, it is just a string.

I'm encouraging you to use the timestamp because it is more useful in a general sense - it is better practice to store dates as integer values. There is also not a single advantage (that I can think of) of storing a string

Now I still don't get why the hell you need to get the date out of a database if the rest of the email message is done using POST variables? If the message has only just been submitted (hence POST) you can just use the current date....
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

PHP Code: [ Select ]
 
<?php
 
 
 
//extract($_REQUEST);
 
 
 
if ($_POST['submit'])
 
{
 
$user="building";
 
$host="localhost";
 
$password="iNGereNDoi";
 
$database="building";
 
$connection=mysql_connect($host,$user,$password) or die ("could not connect to server");
 
$db=mysql_select_db($database,$connection);
 
$sql = "insert into gstrialformaa(my_date, name, email, contactaddress, mobile, workhometel, contactpostcode, projectpostcode, doyouneed, designstyle, project, uses, engineer, partywall, architect, projectmanager, design, lifestyle, structural, planning, buildingregs, otherhelp, wheelchair, partialeyesight, terraced, familychildern, semidetached, aged, allergy, detached, other, otherneeds, specifyneeds, programtimecompletion, budgetcost, projectdeadline, whybuild, otherpreferences) values ('{$_POST['my_date']}','{$_POST['name']}','{$_POST['email']}','{$_POST['contactaddress']}','{$_POST['mobile']}','{$_POST['workhometel']}','{$_POST['contactpostcode']}','{$_POST['projectpostcode']}','{$_POST['doyouneed']}','{$_POST['designstyle']}','{$_POST['project']}','{$_POST['uses']}','{$_POST['engineer']}','{$_POST['partywall']}','{$_POST['architect']}','{$_POST['projectmanager']}','{$_POST['design']}','{$_POST['lifestyle']}','{$_POST['structural']}','{$_POST['planning']}','{$_POST['buildingregs']}','{$_POST['otherhelp']}','{$_POST['wheelchair']}','{$_POST['partialeyesight']}','{$_POST['terraced']}','{$_POST['familychildern']}','{$_POST['semidetached']}','{$_POST['aged']}','{$_POST['allergy']}','{$_POST['detached']}','{$_POST['other']}','{$_POST['otherneeds']}','{$_POST['specifyneeds']}','{$_POST['programtimecompletion']}','{$_POST['budgetcost']}','{$_POST['projectdeadline']}','{$_POST['whybuild']}','{$_POST['otherpreferences']}')";
 
$result = mysql_query($sql) or print(mysql_error());
 
//mail($to, $subject, $msg, $additional_headers);
 
mail($_POST['email'],'hello there','Hello '.$_POST['name'].', thank you for filling out the form ', "From: athompson@building-doctors.com");
 
echo "<table border=1 cellpadding=2 cellspacing=2 class=biggertext><tr><td>";
 
echo "</tr></td><tr><td><img src=images/cr_header.gif></tr></td><tr><td>";
 
echo 'Hello '.$_POST['name'].', thank you for filling out the form ';
 
echo "</tr></td></table>";
 
echo "<body onLoad=redirect() text=#000000 link=#00FFFF vlink=#C0C0C0>";
 
}
 
else
 
{
 
?>
  1.  
  2. <?php
  3.  
  4.  
  5.  
  6. //extract($_REQUEST);
  7.  
  8.  
  9.  
  10. if ($_POST['submit'])
  11.  
  12. {
  13.  
  14. $user="building";
  15.  
  16. $host="localhost";
  17.  
  18. $password="iNGereNDoi";
  19.  
  20. $database="building";
  21.  
  22. $connection=mysql_connect($host,$user,$password) or die ("could not connect to server");
  23.  
  24. $db=mysql_select_db($database,$connection);
  25.  
  26. $sql = "insert into gstrialformaa(my_date, name, email, contactaddress, mobile, workhometel, contactpostcode, projectpostcode, doyouneed, designstyle, project, uses, engineer, partywall, architect, projectmanager, design, lifestyle, structural, planning, buildingregs, otherhelp, wheelchair, partialeyesight, terraced, familychildern, semidetached, aged, allergy, detached, other, otherneeds, specifyneeds, programtimecompletion, budgetcost, projectdeadline, whybuild, otherpreferences) values ('{$_POST['my_date']}','{$_POST['name']}','{$_POST['email']}','{$_POST['contactaddress']}','{$_POST['mobile']}','{$_POST['workhometel']}','{$_POST['contactpostcode']}','{$_POST['projectpostcode']}','{$_POST['doyouneed']}','{$_POST['designstyle']}','{$_POST['project']}','{$_POST['uses']}','{$_POST['engineer']}','{$_POST['partywall']}','{$_POST['architect']}','{$_POST['projectmanager']}','{$_POST['design']}','{$_POST['lifestyle']}','{$_POST['structural']}','{$_POST['planning']}','{$_POST['buildingregs']}','{$_POST['otherhelp']}','{$_POST['wheelchair']}','{$_POST['partialeyesight']}','{$_POST['terraced']}','{$_POST['familychildern']}','{$_POST['semidetached']}','{$_POST['aged']}','{$_POST['allergy']}','{$_POST['detached']}','{$_POST['other']}','{$_POST['otherneeds']}','{$_POST['specifyneeds']}','{$_POST['programtimecompletion']}','{$_POST['budgetcost']}','{$_POST['projectdeadline']}','{$_POST['whybuild']}','{$_POST['otherpreferences']}')";
  27.  
  28. $result = mysql_query($sql) or print(mysql_error());
  29.  
  30. //mail($to, $subject, $msg, $additional_headers);
  31.  
  32. mail($_POST['email'],'hello there','Hello '.$_POST['name'].', thank you for filling out the form ', "From: athompson@building-doctors.com");
  33.  
  34. echo "<table border=1 cellpadding=2 cellspacing=2 class=biggertext><tr><td>";
  35.  
  36. echo "</tr></td><tr><td><img src=images/cr_header.gif></tr></td><tr><td>";
  37.  
  38. echo 'Hello '.$_POST['name'].', thank you for filling out the form ';
  39.  
  40. echo "</tr></td></table>";
  41.  
  42. echo "<body onLoad=redirect() text=#000000 link=#00FFFF vlink=#C0C0C0>";
  43.  
  44. }
  45.  
  46. else
  47.  
  48. {
  49.  
  50. ?>
the form starts here:
Code: [ Select ]
<body leftmargin="0" topmargin="0">


when you submit the form to be sent to the database it then also autoresponds you the fact that it has been submitted. so maybe it isnt really getting the name and other details out of the database but just posting the name and email address as it is being submitted. whichever the case i want it to do the same for the date and other details that i will post out. this is what i am asking about the date. in the coding above would it be better to use the strtime format or the timestamp format. the timestamp is going to be used as a reference as in: 'o yes this form was fill in 2 weeks ago'

how about the date_format function? is that a viable instruction to use?

Post Information

  • Total Posts in this topic: 11 posts
  • Users browsing this forum: No registered users and 56 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.