Converting Date Input to 12 hour format PHP [duplicate]












0
















This question already has an answer here:




  • How do I convert date/time from 24-hour format to 12-hour AM/PM?

    3 answers




I need some help figuring out how to change a date input field into a 12 hour format so I can pass the variable to a email sending script. I am trying to be able to have a online time sheet so that employees can enter there time online. Problem is I need the time, 12 hour format so that the accountant can better read the times and enter them faster. I am VERY new to PHP and would appreciate any help. Comment with any questions.



This is what it look like when it emails:



TIMESHEET FROM EMAIL



HTML:



<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>TimeSheet</title>
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>


<div class="content">
<form class="timesheetform" action="form.php" method="post">
<p class="header">GRADY ELECTRIC<br>TIME SHEET</p>
<input type="text" name="employee" placeholder="Employee Name">
<input type="text" name="email" placeholder="Email">
<input type="number" name="job#" placeholder="Job # (see work order log)">
<p class="mini-heading">Date:</p>
<input class="across" type="date" name="date">

<p class="sub-heading">Start Time:</p>
<input class="across" type="time" name="starttime" placeholder="Start Time">

<p class="sub-heading">Lunch Duration:</p>
<input type="number" name="lunch" placeholder="(Enter In Minutes)">

<p class="sub-heading across">Stop Time:</p>
<input class="across" type="time" name="stoptime" placeholder="Stop Time">

<p class="sub-heading">Total Hours:</p>
<input type="text" name="totalhours" placeholder="Total Hours">

<p class="sub-heading">Drive Time:</p>
<input type="text" name="drivetime" placeholder="Drive Time">


<p class="sub-heading">Job Complete?</p>

<div class="radiobuttons">
<div class="radiobtnoption">
<p>Yes</p>
<input type="radio" name="radiobtn" value="YES">
</div>
<div class="radiobtnoption">
<p>No</p>
<input type="radio" name="radiobtn" value="NO">
</div>
</div>



<input type="text" name="customer" placeholder="Customer (ex: Brascia)">
<input type="text" name="location" placeholder="Location/Address">
<textarea name="jobdescription" placeholder="Job Description"></textarea>



<div class="materialssection">
<input class="materialsinfo" type="text" name="m-1" placeholder="Materials:">
<input class="materialsinfo" type="text" name="q-1" placeholder="Qty:">
<input class="materialsinfo" type="text" name="e-1" placeholder="Each:">
<input class="materialsinfo" type="text" name="t-1" placeholder="Total">
</div>
<div class="materialssection">
<input class="materialsinfo" type="text" name="m-2" placeholder="Materials:">
<input class="materialsinfo" type="text" name="q-2" placeholder="Qty:">
<input class="materialsinfo" type="text" name="e-2" placeholder="Each:">
<input class="materialsinfo" type="text" name="t-2" placeholder="Total">
</div>
<div class="materialssection">
<input class="materialsinfo" type="text" name="m-3" placeholder="Materials:">
<input class="materialsinfo" type="text" name="q-3" placeholder="Qty:">
<input class="materialsinfo" type="text" name="e-3" placeholder="Each:">
<input class="materialsinfo" type="text" name="t-3" placeholder="Total">
</div>
<div class="materialssection">
<input class="materialsinfo" type="text" name="m-4" placeholder="Materials:">
<input class="materialsinfo" type="text" name="q-4" placeholder="Qty:">
<input class="materialsinfo" type="text" name="e-4" placeholder="Each:">
<input class="materialsinfo" type="text" name="t-4" placeholder="Total">
</div>
<div class="materialssection">
<input class="materialsinfo" type="text" name="m-5" placeholder="Materials:">
<input class="materialsinfo" type="text" name="q-5" placeholder="Qty:">
<input class="materialsinfo" type="text" name="e-5" placeholder="Each:">
<input class="materialsinfo" type="text" name="t-5" placeholder="Total">
</div>
<div class="materialssection">
<input class="materialsinfo" type="text" name="m-6" placeholder="Materials:">
<input class="materialsinfo" type="text" name="q-6" placeholder="Qty:">
<input class="materialsinfo" type="text" name="e-6" placeholder="Each:">
<input class="materialsinfo" type="text" name="t-6" placeholder="Total">
</div>
<div class="materialssection">
<input class="materialsinfo" type="text" name="m-7" placeholder="Materials:">
<input class="materialsinfo" type="text" name="q-7" placeholder="Qty:">
<input class="materialsinfo" type="text" name="e-7" placeholder="Each:">
<input class="materialsinfo" type="text" name="t-7" placeholder="Total">
</div>

<textarea name="notes" placeholder="Notes:"></textarea>
<button type="submit" name="submit">Submit</button>
</form>


</div>
</body>
</html>


PHP:



<?php
if (isset($_POST['submit'])) {

$email = $_POST['email'];
$to = "example@example.com, $email";
$subject = "New TimeSheet";
$name = $_POST['employee'];
$date = $_POST['date'];
$jobnum = $_POST['job#'];
$radio = $_POST['radiobtn'];
$customer = $_POST['customer'];
$address = $_POST['location'];
$jobdes = $_POST['jobdescription'];
$starttime = mktime($_POST['starttime']);
$lunchtime = $_POST['lunch'];
$stoptime = mktime($_POST['stoptime']);
$totalhours = $_POST['totalhours'];
$drivetime = $_POST['drivetime'];
$notes = $_POST['notes'];


$m1 = $_POST['m-1'];
$m2 = $_POST['m-2'];
$m3 = $_POST['m-3'];
$m4 = $_POST['m-4'];
$m5 = $_POST['m-5'];
$m6 = $_POST['m-6'];
$m7 = $_POST['m-7'];

$q1 = $_POST['q-1'];
$q2 = $_POST['q-2'];
$q3 = $_POST['q-3'];
$q4 = $_POST['q-4'];
$q5 = $_POST['q-5'];
$q6 = $_POST['q-6'];
$q7 = $_POST['q-7'];

$e1 = $_POST['e-1'];
$e2 = $_POST['e-2'];
$e3 = $_POST['e-3'];
$e4 = $_POST['e-4'];
$e5 = $_POST['e-5'];
$e6 = $_POST['e-6'];
$e7 = $_POST['e-7'];

$t1 = $_POST['t-1'];
$t2 = $_POST['t-2'];
$t3 = $_POST['t-3'];
$t4 = $_POST['t-4'];
$t5 = $_POST['t-5'];
$t6 = $_POST['t-6'];
$t7 = $_POST['t-7'];

$message = "<html><body>";
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: lightgrey;'><td><strong>Tech Name:</strong> </td><td>" .$name. "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Job #:</strong> </td><td>" .$jobnum. "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Date:</strong> </td><td>" . $date . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Start Time:</strong> </td><td>" . date("h:i:a", $starttime) . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Lunch Duration:</strong> </td><td>" . $lunchtime . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Stop Time:</strong> </td><td>" . date("h:i:a", $starttime) . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Total Hours:</strong> </td><td>" . $totalhours . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Drive Time:</strong> </td><td>" . $drivetime . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Job Complete:</strong> </td><td>" . $radio . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Customer:</strong> </td><td>" . $customer . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Location/Address:</strong> </td><td>" . $address . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Job Description:</strong> </td><td>" . $jobdes . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Notes:</strong> </td><td>" . $notes . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Materials:</strong></td> <td><strong>Qty:</strong></td> <td><strong>Each:</strong></td> <td><strong>Total:</strong></td></tr>";
$message .= "<tr style='background: lightgrey;'><td>$m1</td><td>$q1</td><td>$e1</td><td>$t1</td>";
$message .= "<tr style='background: lightgrey;'><td>$m2</td><td>$q2</td><td>$e2</td><td>$t2</td>";
$message .= "<tr style='background: lightgrey;'><td>$m3</td><td>$q3</td><td>$e3</td><td>$t3</td>";
$message .= "<tr style='background: lightgrey;'><td>$m4</td><td>$q4</td><td>$e4</td><td>$t4</td>";
$message .= "<tr style='background: lightgrey;'><td>$m5</td><td>$q5</td><td>$e5</td><td>$t5</td>";
$message .= "<tr style='background: lightgrey;'><td>$m6</td><td>$q6</td><td>$e6</td><td>$t6</td>";
$message .= "<tr style='background: lightgrey;'><td>$m7</td><td>$q7</td><td>$e7</td><td>$t7</td>";
$message .= "</table>";
$message .= "</body></html>";



// Always set content-type when sending HTML email
$headers = "From: forms@gradyelectricforms.comrn";
$headers .= "Content-Type: text/html";

mail( $to, $subject, $message, $headers );
header("location: http://www.gradyelectricinc.com", true, 301 ); exit;
}
?>









share|improve this question















marked as duplicate by Machavity php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 0:09


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    0
















    This question already has an answer here:




    • How do I convert date/time from 24-hour format to 12-hour AM/PM?

      3 answers




    I need some help figuring out how to change a date input field into a 12 hour format so I can pass the variable to a email sending script. I am trying to be able to have a online time sheet so that employees can enter there time online. Problem is I need the time, 12 hour format so that the accountant can better read the times and enter them faster. I am VERY new to PHP and would appreciate any help. Comment with any questions.



    This is what it look like when it emails:



    TIMESHEET FROM EMAIL



    HTML:



    <!DOCTYPE html>
    <html lang="en" dir="ltr">
    <head>
    <meta charset="utf-8">
    <title>TimeSheet</title>
    <link rel="stylesheet" href="style.css">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>

    <body>


    <div class="content">
    <form class="timesheetform" action="form.php" method="post">
    <p class="header">GRADY ELECTRIC<br>TIME SHEET</p>
    <input type="text" name="employee" placeholder="Employee Name">
    <input type="text" name="email" placeholder="Email">
    <input type="number" name="job#" placeholder="Job # (see work order log)">
    <p class="mini-heading">Date:</p>
    <input class="across" type="date" name="date">

    <p class="sub-heading">Start Time:</p>
    <input class="across" type="time" name="starttime" placeholder="Start Time">

    <p class="sub-heading">Lunch Duration:</p>
    <input type="number" name="lunch" placeholder="(Enter In Minutes)">

    <p class="sub-heading across">Stop Time:</p>
    <input class="across" type="time" name="stoptime" placeholder="Stop Time">

    <p class="sub-heading">Total Hours:</p>
    <input type="text" name="totalhours" placeholder="Total Hours">

    <p class="sub-heading">Drive Time:</p>
    <input type="text" name="drivetime" placeholder="Drive Time">


    <p class="sub-heading">Job Complete?</p>

    <div class="radiobuttons">
    <div class="radiobtnoption">
    <p>Yes</p>
    <input type="radio" name="radiobtn" value="YES">
    </div>
    <div class="radiobtnoption">
    <p>No</p>
    <input type="radio" name="radiobtn" value="NO">
    </div>
    </div>



    <input type="text" name="customer" placeholder="Customer (ex: Brascia)">
    <input type="text" name="location" placeholder="Location/Address">
    <textarea name="jobdescription" placeholder="Job Description"></textarea>



    <div class="materialssection">
    <input class="materialsinfo" type="text" name="m-1" placeholder="Materials:">
    <input class="materialsinfo" type="text" name="q-1" placeholder="Qty:">
    <input class="materialsinfo" type="text" name="e-1" placeholder="Each:">
    <input class="materialsinfo" type="text" name="t-1" placeholder="Total">
    </div>
    <div class="materialssection">
    <input class="materialsinfo" type="text" name="m-2" placeholder="Materials:">
    <input class="materialsinfo" type="text" name="q-2" placeholder="Qty:">
    <input class="materialsinfo" type="text" name="e-2" placeholder="Each:">
    <input class="materialsinfo" type="text" name="t-2" placeholder="Total">
    </div>
    <div class="materialssection">
    <input class="materialsinfo" type="text" name="m-3" placeholder="Materials:">
    <input class="materialsinfo" type="text" name="q-3" placeholder="Qty:">
    <input class="materialsinfo" type="text" name="e-3" placeholder="Each:">
    <input class="materialsinfo" type="text" name="t-3" placeholder="Total">
    </div>
    <div class="materialssection">
    <input class="materialsinfo" type="text" name="m-4" placeholder="Materials:">
    <input class="materialsinfo" type="text" name="q-4" placeholder="Qty:">
    <input class="materialsinfo" type="text" name="e-4" placeholder="Each:">
    <input class="materialsinfo" type="text" name="t-4" placeholder="Total">
    </div>
    <div class="materialssection">
    <input class="materialsinfo" type="text" name="m-5" placeholder="Materials:">
    <input class="materialsinfo" type="text" name="q-5" placeholder="Qty:">
    <input class="materialsinfo" type="text" name="e-5" placeholder="Each:">
    <input class="materialsinfo" type="text" name="t-5" placeholder="Total">
    </div>
    <div class="materialssection">
    <input class="materialsinfo" type="text" name="m-6" placeholder="Materials:">
    <input class="materialsinfo" type="text" name="q-6" placeholder="Qty:">
    <input class="materialsinfo" type="text" name="e-6" placeholder="Each:">
    <input class="materialsinfo" type="text" name="t-6" placeholder="Total">
    </div>
    <div class="materialssection">
    <input class="materialsinfo" type="text" name="m-7" placeholder="Materials:">
    <input class="materialsinfo" type="text" name="q-7" placeholder="Qty:">
    <input class="materialsinfo" type="text" name="e-7" placeholder="Each:">
    <input class="materialsinfo" type="text" name="t-7" placeholder="Total">
    </div>

    <textarea name="notes" placeholder="Notes:"></textarea>
    <button type="submit" name="submit">Submit</button>
    </form>


    </div>
    </body>
    </html>


    PHP:



    <?php
    if (isset($_POST['submit'])) {

    $email = $_POST['email'];
    $to = "example@example.com, $email";
    $subject = "New TimeSheet";
    $name = $_POST['employee'];
    $date = $_POST['date'];
    $jobnum = $_POST['job#'];
    $radio = $_POST['radiobtn'];
    $customer = $_POST['customer'];
    $address = $_POST['location'];
    $jobdes = $_POST['jobdescription'];
    $starttime = mktime($_POST['starttime']);
    $lunchtime = $_POST['lunch'];
    $stoptime = mktime($_POST['stoptime']);
    $totalhours = $_POST['totalhours'];
    $drivetime = $_POST['drivetime'];
    $notes = $_POST['notes'];


    $m1 = $_POST['m-1'];
    $m2 = $_POST['m-2'];
    $m3 = $_POST['m-3'];
    $m4 = $_POST['m-4'];
    $m5 = $_POST['m-5'];
    $m6 = $_POST['m-6'];
    $m7 = $_POST['m-7'];

    $q1 = $_POST['q-1'];
    $q2 = $_POST['q-2'];
    $q3 = $_POST['q-3'];
    $q4 = $_POST['q-4'];
    $q5 = $_POST['q-5'];
    $q6 = $_POST['q-6'];
    $q7 = $_POST['q-7'];

    $e1 = $_POST['e-1'];
    $e2 = $_POST['e-2'];
    $e3 = $_POST['e-3'];
    $e4 = $_POST['e-4'];
    $e5 = $_POST['e-5'];
    $e6 = $_POST['e-6'];
    $e7 = $_POST['e-7'];

    $t1 = $_POST['t-1'];
    $t2 = $_POST['t-2'];
    $t3 = $_POST['t-3'];
    $t4 = $_POST['t-4'];
    $t5 = $_POST['t-5'];
    $t6 = $_POST['t-6'];
    $t7 = $_POST['t-7'];

    $message = "<html><body>";
    $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
    $message .= "<tr style='background: lightgrey;'><td><strong>Tech Name:</strong> </td><td>" .$name. "</td></tr>";
    $message .= "<tr style='background: lightgrey;'><td><strong>Job #:</strong> </td><td>" .$jobnum. "</td></tr>";
    $message .= "<tr style='background: lightgrey;'><td><strong>Date:</strong> </td><td>" . $date . "</td></tr>";
    $message .= "<tr style='background: lightgrey;'><td><strong>Start Time:</strong> </td><td>" . date("h:i:a", $starttime) . "</td></tr>";
    $message .= "<tr style='background: lightgrey;'><td><strong>Lunch Duration:</strong> </td><td>" . $lunchtime . "</td></tr>";
    $message .= "<tr style='background: lightgrey;'><td><strong>Stop Time:</strong> </td><td>" . date("h:i:a", $starttime) . "</td></tr>";
    $message .= "<tr style='background: lightgrey;'><td><strong>Total Hours:</strong> </td><td>" . $totalhours . "</td></tr>";
    $message .= "<tr style='background: lightgrey;'><td><strong>Drive Time:</strong> </td><td>" . $drivetime . "</td></tr>";
    $message .= "<tr style='background: lightgrey;'><td><strong>Job Complete:</strong> </td><td>" . $radio . "</td></tr>";
    $message .= "<tr style='background: lightgrey;'><td><strong>Customer:</strong> </td><td>" . $customer . "</td></tr>";
    $message .= "<tr style='background: lightgrey;'><td><strong>Location/Address:</strong> </td><td>" . $address . "</td></tr>";
    $message .= "<tr style='background: lightgrey;'><td><strong>Job Description:</strong> </td><td>" . $jobdes . "</td></tr>";
    $message .= "<tr style='background: lightgrey;'><td><strong>Notes:</strong> </td><td>" . $notes . "</td></tr>";
    $message .= "<tr style='background: lightgrey;'><td><strong>Materials:</strong></td> <td><strong>Qty:</strong></td> <td><strong>Each:</strong></td> <td><strong>Total:</strong></td></tr>";
    $message .= "<tr style='background: lightgrey;'><td>$m1</td><td>$q1</td><td>$e1</td><td>$t1</td>";
    $message .= "<tr style='background: lightgrey;'><td>$m2</td><td>$q2</td><td>$e2</td><td>$t2</td>";
    $message .= "<tr style='background: lightgrey;'><td>$m3</td><td>$q3</td><td>$e3</td><td>$t3</td>";
    $message .= "<tr style='background: lightgrey;'><td>$m4</td><td>$q4</td><td>$e4</td><td>$t4</td>";
    $message .= "<tr style='background: lightgrey;'><td>$m5</td><td>$q5</td><td>$e5</td><td>$t5</td>";
    $message .= "<tr style='background: lightgrey;'><td>$m6</td><td>$q6</td><td>$e6</td><td>$t6</td>";
    $message .= "<tr style='background: lightgrey;'><td>$m7</td><td>$q7</td><td>$e7</td><td>$t7</td>";
    $message .= "</table>";
    $message .= "</body></html>";



    // Always set content-type when sending HTML email
    $headers = "From: forms@gradyelectricforms.comrn";
    $headers .= "Content-Type: text/html";

    mail( $to, $subject, $message, $headers );
    header("location: http://www.gradyelectricinc.com", true, 301 ); exit;
    }
    ?>









    share|improve this question















    marked as duplicate by Machavity php
    Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 21 '18 at 0:09


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      0












      0








      0









      This question already has an answer here:




      • How do I convert date/time from 24-hour format to 12-hour AM/PM?

        3 answers




      I need some help figuring out how to change a date input field into a 12 hour format so I can pass the variable to a email sending script. I am trying to be able to have a online time sheet so that employees can enter there time online. Problem is I need the time, 12 hour format so that the accountant can better read the times and enter them faster. I am VERY new to PHP and would appreciate any help. Comment with any questions.



      This is what it look like when it emails:



      TIMESHEET FROM EMAIL



      HTML:



      <!DOCTYPE html>
      <html lang="en" dir="ltr">
      <head>
      <meta charset="utf-8">
      <title>TimeSheet</title>
      <link rel="stylesheet" href="style.css">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      </head>

      <body>


      <div class="content">
      <form class="timesheetform" action="form.php" method="post">
      <p class="header">GRADY ELECTRIC<br>TIME SHEET</p>
      <input type="text" name="employee" placeholder="Employee Name">
      <input type="text" name="email" placeholder="Email">
      <input type="number" name="job#" placeholder="Job # (see work order log)">
      <p class="mini-heading">Date:</p>
      <input class="across" type="date" name="date">

      <p class="sub-heading">Start Time:</p>
      <input class="across" type="time" name="starttime" placeholder="Start Time">

      <p class="sub-heading">Lunch Duration:</p>
      <input type="number" name="lunch" placeholder="(Enter In Minutes)">

      <p class="sub-heading across">Stop Time:</p>
      <input class="across" type="time" name="stoptime" placeholder="Stop Time">

      <p class="sub-heading">Total Hours:</p>
      <input type="text" name="totalhours" placeholder="Total Hours">

      <p class="sub-heading">Drive Time:</p>
      <input type="text" name="drivetime" placeholder="Drive Time">


      <p class="sub-heading">Job Complete?</p>

      <div class="radiobuttons">
      <div class="radiobtnoption">
      <p>Yes</p>
      <input type="radio" name="radiobtn" value="YES">
      </div>
      <div class="radiobtnoption">
      <p>No</p>
      <input type="radio" name="radiobtn" value="NO">
      </div>
      </div>



      <input type="text" name="customer" placeholder="Customer (ex: Brascia)">
      <input type="text" name="location" placeholder="Location/Address">
      <textarea name="jobdescription" placeholder="Job Description"></textarea>



      <div class="materialssection">
      <input class="materialsinfo" type="text" name="m-1" placeholder="Materials:">
      <input class="materialsinfo" type="text" name="q-1" placeholder="Qty:">
      <input class="materialsinfo" type="text" name="e-1" placeholder="Each:">
      <input class="materialsinfo" type="text" name="t-1" placeholder="Total">
      </div>
      <div class="materialssection">
      <input class="materialsinfo" type="text" name="m-2" placeholder="Materials:">
      <input class="materialsinfo" type="text" name="q-2" placeholder="Qty:">
      <input class="materialsinfo" type="text" name="e-2" placeholder="Each:">
      <input class="materialsinfo" type="text" name="t-2" placeholder="Total">
      </div>
      <div class="materialssection">
      <input class="materialsinfo" type="text" name="m-3" placeholder="Materials:">
      <input class="materialsinfo" type="text" name="q-3" placeholder="Qty:">
      <input class="materialsinfo" type="text" name="e-3" placeholder="Each:">
      <input class="materialsinfo" type="text" name="t-3" placeholder="Total">
      </div>
      <div class="materialssection">
      <input class="materialsinfo" type="text" name="m-4" placeholder="Materials:">
      <input class="materialsinfo" type="text" name="q-4" placeholder="Qty:">
      <input class="materialsinfo" type="text" name="e-4" placeholder="Each:">
      <input class="materialsinfo" type="text" name="t-4" placeholder="Total">
      </div>
      <div class="materialssection">
      <input class="materialsinfo" type="text" name="m-5" placeholder="Materials:">
      <input class="materialsinfo" type="text" name="q-5" placeholder="Qty:">
      <input class="materialsinfo" type="text" name="e-5" placeholder="Each:">
      <input class="materialsinfo" type="text" name="t-5" placeholder="Total">
      </div>
      <div class="materialssection">
      <input class="materialsinfo" type="text" name="m-6" placeholder="Materials:">
      <input class="materialsinfo" type="text" name="q-6" placeholder="Qty:">
      <input class="materialsinfo" type="text" name="e-6" placeholder="Each:">
      <input class="materialsinfo" type="text" name="t-6" placeholder="Total">
      </div>
      <div class="materialssection">
      <input class="materialsinfo" type="text" name="m-7" placeholder="Materials:">
      <input class="materialsinfo" type="text" name="q-7" placeholder="Qty:">
      <input class="materialsinfo" type="text" name="e-7" placeholder="Each:">
      <input class="materialsinfo" type="text" name="t-7" placeholder="Total">
      </div>

      <textarea name="notes" placeholder="Notes:"></textarea>
      <button type="submit" name="submit">Submit</button>
      </form>


      </div>
      </body>
      </html>


      PHP:



      <?php
      if (isset($_POST['submit'])) {

      $email = $_POST['email'];
      $to = "example@example.com, $email";
      $subject = "New TimeSheet";
      $name = $_POST['employee'];
      $date = $_POST['date'];
      $jobnum = $_POST['job#'];
      $radio = $_POST['radiobtn'];
      $customer = $_POST['customer'];
      $address = $_POST['location'];
      $jobdes = $_POST['jobdescription'];
      $starttime = mktime($_POST['starttime']);
      $lunchtime = $_POST['lunch'];
      $stoptime = mktime($_POST['stoptime']);
      $totalhours = $_POST['totalhours'];
      $drivetime = $_POST['drivetime'];
      $notes = $_POST['notes'];


      $m1 = $_POST['m-1'];
      $m2 = $_POST['m-2'];
      $m3 = $_POST['m-3'];
      $m4 = $_POST['m-4'];
      $m5 = $_POST['m-5'];
      $m6 = $_POST['m-6'];
      $m7 = $_POST['m-7'];

      $q1 = $_POST['q-1'];
      $q2 = $_POST['q-2'];
      $q3 = $_POST['q-3'];
      $q4 = $_POST['q-4'];
      $q5 = $_POST['q-5'];
      $q6 = $_POST['q-6'];
      $q7 = $_POST['q-7'];

      $e1 = $_POST['e-1'];
      $e2 = $_POST['e-2'];
      $e3 = $_POST['e-3'];
      $e4 = $_POST['e-4'];
      $e5 = $_POST['e-5'];
      $e6 = $_POST['e-6'];
      $e7 = $_POST['e-7'];

      $t1 = $_POST['t-1'];
      $t2 = $_POST['t-2'];
      $t3 = $_POST['t-3'];
      $t4 = $_POST['t-4'];
      $t5 = $_POST['t-5'];
      $t6 = $_POST['t-6'];
      $t7 = $_POST['t-7'];

      $message = "<html><body>";
      $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
      $message .= "<tr style='background: lightgrey;'><td><strong>Tech Name:</strong> </td><td>" .$name. "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Job #:</strong> </td><td>" .$jobnum. "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Date:</strong> </td><td>" . $date . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Start Time:</strong> </td><td>" . date("h:i:a", $starttime) . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Lunch Duration:</strong> </td><td>" . $lunchtime . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Stop Time:</strong> </td><td>" . date("h:i:a", $starttime) . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Total Hours:</strong> </td><td>" . $totalhours . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Drive Time:</strong> </td><td>" . $drivetime . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Job Complete:</strong> </td><td>" . $radio . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Customer:</strong> </td><td>" . $customer . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Location/Address:</strong> </td><td>" . $address . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Job Description:</strong> </td><td>" . $jobdes . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Notes:</strong> </td><td>" . $notes . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Materials:</strong></td> <td><strong>Qty:</strong></td> <td><strong>Each:</strong></td> <td><strong>Total:</strong></td></tr>";
      $message .= "<tr style='background: lightgrey;'><td>$m1</td><td>$q1</td><td>$e1</td><td>$t1</td>";
      $message .= "<tr style='background: lightgrey;'><td>$m2</td><td>$q2</td><td>$e2</td><td>$t2</td>";
      $message .= "<tr style='background: lightgrey;'><td>$m3</td><td>$q3</td><td>$e3</td><td>$t3</td>";
      $message .= "<tr style='background: lightgrey;'><td>$m4</td><td>$q4</td><td>$e4</td><td>$t4</td>";
      $message .= "<tr style='background: lightgrey;'><td>$m5</td><td>$q5</td><td>$e5</td><td>$t5</td>";
      $message .= "<tr style='background: lightgrey;'><td>$m6</td><td>$q6</td><td>$e6</td><td>$t6</td>";
      $message .= "<tr style='background: lightgrey;'><td>$m7</td><td>$q7</td><td>$e7</td><td>$t7</td>";
      $message .= "</table>";
      $message .= "</body></html>";



      // Always set content-type when sending HTML email
      $headers = "From: forms@gradyelectricforms.comrn";
      $headers .= "Content-Type: text/html";

      mail( $to, $subject, $message, $headers );
      header("location: http://www.gradyelectricinc.com", true, 301 ); exit;
      }
      ?>









      share|improve this question

















      This question already has an answer here:




      • How do I convert date/time from 24-hour format to 12-hour AM/PM?

        3 answers




      I need some help figuring out how to change a date input field into a 12 hour format so I can pass the variable to a email sending script. I am trying to be able to have a online time sheet so that employees can enter there time online. Problem is I need the time, 12 hour format so that the accountant can better read the times and enter them faster. I am VERY new to PHP and would appreciate any help. Comment with any questions.



      This is what it look like when it emails:



      TIMESHEET FROM EMAIL



      HTML:



      <!DOCTYPE html>
      <html lang="en" dir="ltr">
      <head>
      <meta charset="utf-8">
      <title>TimeSheet</title>
      <link rel="stylesheet" href="style.css">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      </head>

      <body>


      <div class="content">
      <form class="timesheetform" action="form.php" method="post">
      <p class="header">GRADY ELECTRIC<br>TIME SHEET</p>
      <input type="text" name="employee" placeholder="Employee Name">
      <input type="text" name="email" placeholder="Email">
      <input type="number" name="job#" placeholder="Job # (see work order log)">
      <p class="mini-heading">Date:</p>
      <input class="across" type="date" name="date">

      <p class="sub-heading">Start Time:</p>
      <input class="across" type="time" name="starttime" placeholder="Start Time">

      <p class="sub-heading">Lunch Duration:</p>
      <input type="number" name="lunch" placeholder="(Enter In Minutes)">

      <p class="sub-heading across">Stop Time:</p>
      <input class="across" type="time" name="stoptime" placeholder="Stop Time">

      <p class="sub-heading">Total Hours:</p>
      <input type="text" name="totalhours" placeholder="Total Hours">

      <p class="sub-heading">Drive Time:</p>
      <input type="text" name="drivetime" placeholder="Drive Time">


      <p class="sub-heading">Job Complete?</p>

      <div class="radiobuttons">
      <div class="radiobtnoption">
      <p>Yes</p>
      <input type="radio" name="radiobtn" value="YES">
      </div>
      <div class="radiobtnoption">
      <p>No</p>
      <input type="radio" name="radiobtn" value="NO">
      </div>
      </div>



      <input type="text" name="customer" placeholder="Customer (ex: Brascia)">
      <input type="text" name="location" placeholder="Location/Address">
      <textarea name="jobdescription" placeholder="Job Description"></textarea>



      <div class="materialssection">
      <input class="materialsinfo" type="text" name="m-1" placeholder="Materials:">
      <input class="materialsinfo" type="text" name="q-1" placeholder="Qty:">
      <input class="materialsinfo" type="text" name="e-1" placeholder="Each:">
      <input class="materialsinfo" type="text" name="t-1" placeholder="Total">
      </div>
      <div class="materialssection">
      <input class="materialsinfo" type="text" name="m-2" placeholder="Materials:">
      <input class="materialsinfo" type="text" name="q-2" placeholder="Qty:">
      <input class="materialsinfo" type="text" name="e-2" placeholder="Each:">
      <input class="materialsinfo" type="text" name="t-2" placeholder="Total">
      </div>
      <div class="materialssection">
      <input class="materialsinfo" type="text" name="m-3" placeholder="Materials:">
      <input class="materialsinfo" type="text" name="q-3" placeholder="Qty:">
      <input class="materialsinfo" type="text" name="e-3" placeholder="Each:">
      <input class="materialsinfo" type="text" name="t-3" placeholder="Total">
      </div>
      <div class="materialssection">
      <input class="materialsinfo" type="text" name="m-4" placeholder="Materials:">
      <input class="materialsinfo" type="text" name="q-4" placeholder="Qty:">
      <input class="materialsinfo" type="text" name="e-4" placeholder="Each:">
      <input class="materialsinfo" type="text" name="t-4" placeholder="Total">
      </div>
      <div class="materialssection">
      <input class="materialsinfo" type="text" name="m-5" placeholder="Materials:">
      <input class="materialsinfo" type="text" name="q-5" placeholder="Qty:">
      <input class="materialsinfo" type="text" name="e-5" placeholder="Each:">
      <input class="materialsinfo" type="text" name="t-5" placeholder="Total">
      </div>
      <div class="materialssection">
      <input class="materialsinfo" type="text" name="m-6" placeholder="Materials:">
      <input class="materialsinfo" type="text" name="q-6" placeholder="Qty:">
      <input class="materialsinfo" type="text" name="e-6" placeholder="Each:">
      <input class="materialsinfo" type="text" name="t-6" placeholder="Total">
      </div>
      <div class="materialssection">
      <input class="materialsinfo" type="text" name="m-7" placeholder="Materials:">
      <input class="materialsinfo" type="text" name="q-7" placeholder="Qty:">
      <input class="materialsinfo" type="text" name="e-7" placeholder="Each:">
      <input class="materialsinfo" type="text" name="t-7" placeholder="Total">
      </div>

      <textarea name="notes" placeholder="Notes:"></textarea>
      <button type="submit" name="submit">Submit</button>
      </form>


      </div>
      </body>
      </html>


      PHP:



      <?php
      if (isset($_POST['submit'])) {

      $email = $_POST['email'];
      $to = "example@example.com, $email";
      $subject = "New TimeSheet";
      $name = $_POST['employee'];
      $date = $_POST['date'];
      $jobnum = $_POST['job#'];
      $radio = $_POST['radiobtn'];
      $customer = $_POST['customer'];
      $address = $_POST['location'];
      $jobdes = $_POST['jobdescription'];
      $starttime = mktime($_POST['starttime']);
      $lunchtime = $_POST['lunch'];
      $stoptime = mktime($_POST['stoptime']);
      $totalhours = $_POST['totalhours'];
      $drivetime = $_POST['drivetime'];
      $notes = $_POST['notes'];


      $m1 = $_POST['m-1'];
      $m2 = $_POST['m-2'];
      $m3 = $_POST['m-3'];
      $m4 = $_POST['m-4'];
      $m5 = $_POST['m-5'];
      $m6 = $_POST['m-6'];
      $m7 = $_POST['m-7'];

      $q1 = $_POST['q-1'];
      $q2 = $_POST['q-2'];
      $q3 = $_POST['q-3'];
      $q4 = $_POST['q-4'];
      $q5 = $_POST['q-5'];
      $q6 = $_POST['q-6'];
      $q7 = $_POST['q-7'];

      $e1 = $_POST['e-1'];
      $e2 = $_POST['e-2'];
      $e3 = $_POST['e-3'];
      $e4 = $_POST['e-4'];
      $e5 = $_POST['e-5'];
      $e6 = $_POST['e-6'];
      $e7 = $_POST['e-7'];

      $t1 = $_POST['t-1'];
      $t2 = $_POST['t-2'];
      $t3 = $_POST['t-3'];
      $t4 = $_POST['t-4'];
      $t5 = $_POST['t-5'];
      $t6 = $_POST['t-6'];
      $t7 = $_POST['t-7'];

      $message = "<html><body>";
      $message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
      $message .= "<tr style='background: lightgrey;'><td><strong>Tech Name:</strong> </td><td>" .$name. "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Job #:</strong> </td><td>" .$jobnum. "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Date:</strong> </td><td>" . $date . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Start Time:</strong> </td><td>" . date("h:i:a", $starttime) . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Lunch Duration:</strong> </td><td>" . $lunchtime . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Stop Time:</strong> </td><td>" . date("h:i:a", $starttime) . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Total Hours:</strong> </td><td>" . $totalhours . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Drive Time:</strong> </td><td>" . $drivetime . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Job Complete:</strong> </td><td>" . $radio . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Customer:</strong> </td><td>" . $customer . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Location/Address:</strong> </td><td>" . $address . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Job Description:</strong> </td><td>" . $jobdes . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Notes:</strong> </td><td>" . $notes . "</td></tr>";
      $message .= "<tr style='background: lightgrey;'><td><strong>Materials:</strong></td> <td><strong>Qty:</strong></td> <td><strong>Each:</strong></td> <td><strong>Total:</strong></td></tr>";
      $message .= "<tr style='background: lightgrey;'><td>$m1</td><td>$q1</td><td>$e1</td><td>$t1</td>";
      $message .= "<tr style='background: lightgrey;'><td>$m2</td><td>$q2</td><td>$e2</td><td>$t2</td>";
      $message .= "<tr style='background: lightgrey;'><td>$m3</td><td>$q3</td><td>$e3</td><td>$t3</td>";
      $message .= "<tr style='background: lightgrey;'><td>$m4</td><td>$q4</td><td>$e4</td><td>$t4</td>";
      $message .= "<tr style='background: lightgrey;'><td>$m5</td><td>$q5</td><td>$e5</td><td>$t5</td>";
      $message .= "<tr style='background: lightgrey;'><td>$m6</td><td>$q6</td><td>$e6</td><td>$t6</td>";
      $message .= "<tr style='background: lightgrey;'><td>$m7</td><td>$q7</td><td>$e7</td><td>$t7</td>";
      $message .= "</table>";
      $message .= "</body></html>";



      // Always set content-type when sending HTML email
      $headers = "From: forms@gradyelectricforms.comrn";
      $headers .= "Content-Type: text/html";

      mail( $to, $subject, $message, $headers );
      header("location: http://www.gradyelectricinc.com", true, 301 ); exit;
      }
      ?>




      This question already has an answer here:




      • How do I convert date/time from 24-hour format to 12-hour AM/PM?

        3 answers








      php html date input






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 '18 at 22:24









      Barmar

      425k35248350




      425k35248350










      asked Nov 20 '18 at 22:10









      Technology CentralTechnology Central

      32




      32




      marked as duplicate by Machavity php
      Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 21 '18 at 0:09


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Machavity php
      Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 21 '18 at 0:09


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          0














          Take your time input values, e.g. 17:00:00, and convert it to a Unix timestamp using the strtotime() function.



          $t = strtotime('17:00:00');


          You can then use the date() function to format the timestamp value, e.g. 05:00 am.



          echo date('h:i a', $t);  // 05:00 am


          Two points for your consideration:




          1. Not all browsers support the time input field, e.g. Safari.

          2. In your HTML output, you're using the $startTime value for the stop time.






          share|improve this answer
































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Take your time input values, e.g. 17:00:00, and convert it to a Unix timestamp using the strtotime() function.



            $t = strtotime('17:00:00');


            You can then use the date() function to format the timestamp value, e.g. 05:00 am.



            echo date('h:i a', $t);  // 05:00 am


            Two points for your consideration:




            1. Not all browsers support the time input field, e.g. Safari.

            2. In your HTML output, you're using the $startTime value for the stop time.






            share|improve this answer






























              0














              Take your time input values, e.g. 17:00:00, and convert it to a Unix timestamp using the strtotime() function.



              $t = strtotime('17:00:00');


              You can then use the date() function to format the timestamp value, e.g. 05:00 am.



              echo date('h:i a', $t);  // 05:00 am


              Two points for your consideration:




              1. Not all browsers support the time input field, e.g. Safari.

              2. In your HTML output, you're using the $startTime value for the stop time.






              share|improve this answer




























                0












                0








                0







                Take your time input values, e.g. 17:00:00, and convert it to a Unix timestamp using the strtotime() function.



                $t = strtotime('17:00:00');


                You can then use the date() function to format the timestamp value, e.g. 05:00 am.



                echo date('h:i a', $t);  // 05:00 am


                Two points for your consideration:




                1. Not all browsers support the time input field, e.g. Safari.

                2. In your HTML output, you're using the $startTime value for the stop time.






                share|improve this answer















                Take your time input values, e.g. 17:00:00, and convert it to a Unix timestamp using the strtotime() function.



                $t = strtotime('17:00:00');


                You can then use the date() function to format the timestamp value, e.g. 05:00 am.



                echo date('h:i a', $t);  // 05:00 am


                Two points for your consideration:




                1. Not all browsers support the time input field, e.g. Safari.

                2. In your HTML output, you're using the $startTime value for the stop time.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 21 '18 at 0:06

























                answered Nov 20 '18 at 22:30









                fubarfubar

                9,86121531




                9,86121531















                    Popular posts from this blog

                    MongoDB - Not Authorized To Execute Command

                    How to fix TextFormField cause rebuild widget in Flutter

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith