0

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.

1
  • You need to parse the input into a DateTime object, then format it as you want when mailing. Commented Jan 7, 2014 at 2:26

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.