0

I need to ask some help in converting the date format of a webform.

I'm writing a custom module that send the submissions of my webforms to a third party, however I have to convert my date format from "m/d/Y - H:i a" to the oracle format "DD-MON-YYYY"

I've read up on articles saying that webform uses the site's "short form" but Ideally I'd like to make the conversion in my mod, to keep it contained and because I don't know if changing the "short form" will break anything currently on the site.

This is the line capturing the date field of my form:

 $dob = $submission->data[11]['value'][0];

I'm using Drupal 6.19 and webforms 6.x-3.4 if anyone can give me some suggestions I'd appreciate it. Please let me know if I need to provide more detail.

Thanks! Steph

2 Answers 2

0

This is more of a PHP question, I believe, as you use PHP functions to accomplish this.

<?php   
  $dob = $submission->data[11]['value'][0];
  $time = strtotime($dob);
  $oracle_format = date('d-m-Y', $time);
  // OR
  // $oracle_format = date('d-m-Y', strtotime($dob));
?>

This uses the functions date() and strtotime()

10
  • You are right, it's a PHP question. But I need to ask more help - I just attempted $dob = date('m/d/Y - H:ia'); to test your code and it failed (wsod). I'm really stumped so any additional help is very welcome!
    – StephanieF
    Jul 10, 2013 at 18:14
  • I just edited the question, I had the arguments for date() transposed. Re: your test: that code shouldn't fail. You should turn on debugging ini_set('display_errors', 'On'); or check the logs to see what else is going on. Jul 10, 2013 at 18:21
  • thanks again for more help, I'm getting an interesting result. $date = date('m/d/Y - H:ia'); $oracle_format = date('d-M-Y', strtotime($date)); echo $oracle_format; gives me back the date 31-Dec-1969 rather than today's date. any ideas?
    – StephanieF
    Jul 10, 2013 at 18:27
  • So this is an issue that strtotime() can't convert your format. Can you add an actual value that $submission->data[11]['value'][0]; contains? Jul 10, 2013 at 18:55
  • yes, I've tried his with the same result - $date = date('07/10/2013 - 14:50pm'); $oracle_format = date('d-M-Y', strtotime($date)); I still get 31-Dec-1969
    – StephanieF
    Jul 10, 2013 at 18:58
0

There's an issue with your time string of "07/10/2013 14:50pm" You are mixing 24hr format with AM/PM, which confuses the parser.

Either use date('H:i') [14:50] or date('g:ia') [2:50pm]

4
  • The " - " in the string also messes things up, apparently.
    – Drupac
    Jul 10, 2013 at 20:19
  • Right, but I can't do anything about that "-", do you have any suggestions?
    – StephanieF
    Jul 10, 2013 at 21:10
  • Is it possible to use a preg_replace to remove the date info? since I'm only looking for d-m-Y. and how might I do that?
    – StephanieF
    Jul 10, 2013 at 21:15
  • I think I may have it, if you wouldn't mine trying this? the static value for $date_string will be the dynamic submitted value: $date_string = "07/10/2013 - 17:31pm"; $date_exploded = explode('-',$date_string); $date = strtotime($date_exploded[0]); $date = date('d-M-Y', $date); echo $date;
    – StephanieF
    Jul 10, 2013 at 21:38

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.