简体   繁体   中英

Change Time and Date in HTML Form with PHP Process

I'm a designer and clueless in PHP. Tried working around this but cannot get it to work.

I need to change the date format in a process script file for a simple HTML form. Here's the pertinent parts and the small script:

<?php

$date = strip_tags($_POST['date']);
$start = strip_tags($_POST['start']);

mail( ...etc...);
?>

How do I get the $date and $start (starting time for an event) to email me with date as F j, Y and time as g:i a.

It's currently throwing me the defaults in YYYY-MM-DD and 24 hour time. I tried declaring

$start = time("g:i a");

both after and before the variables are stripped of tags for both $date and $start, but it won't process at all then.

Use the strtotime

$new = date('F j, Y g:i a', strtotime($start));

That will take the formatted time, convert to unix and then format again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM