Visit Our UNIX and Linux User Community


change date format from yyyy/mm/dd to dd/mm/yyyy


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting change date format from yyyy/mm/dd to dd/mm/yyyy
# 1  
Old 11-09-2010
change date format from yyyy/mm/dd to dd/mm/yyyy

(Attention: Green PHP newbie !)
I have an online inquiry form, delivering a date in the form yyyy/mm/dd to my feedback form. If the content passes several checks, the form sends an e-mail to me. All works fine. I just would like to receive the date in the form dd/mm/yyyy. I tried with some code, copied from a forum, but it resolves in a parse error. To make clear what I mean, I better insert the code, which is stripped down to 2 fields ('data_start' and 'data_end'). Can anyone please advise how to do and where to insert such a date conversion in this code below ?
Thanks a lot !

Here is the code: (my modification from line 39 to 47)

Code:
<?php 
session_start(); 
// ------------- CONFIGURABLE SECTION ------------------------
$mailto = 'xxx@xxx' ;
$subject = "Inquiry Form" ;
$formurl = "the contact.php form" ;
$errorurl = "the error message .htm" ;
$thankyouurl = "the thank-you message .htm" ;
// -------------------- END OF CONFIGURABLE SECTION ---------------
// load the variables form address bar
$data_start = $_POST['data_start'] ;
$data_end = $_POST['data_end'] ;
// etc.
// remove the backslashes that normally appears when entering " or '
$data_start = stripslashes($data_start);
$data_end = stripslashes($data_end);
// etc.
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email'])) {
 header("Location: $formurl" );
 exit ;
}
// all fields are empty : arrival, departure, pax and comments ==> error
if(empty($data_start) && empty($data_end) && empty($pax)&& empty($comment)){ 
exit("You have not specified any booking details"); 
exit;
} 
$arrive = explode($_POST['$data_start'],"/");
$arrive[0] =yyyy
$arrive[1] =mm
$arrive[2] =dd
// swap round
$data_start = sprintf("%s/%s/%s",$arrive[2],$arrive[1],$arrive[0]);
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
 header("Location: $errorurl" );
 exit ;
}
if (!isset($_POST['email'])) {
 header("Location: $formurl" );
 exit ;
}
$messageproper =
 "This message was sent from:\n" .
 "$http_referrer\n\n" .
 "------------------------- COMMENTS -------------------------\n\n" .
 "Date of Arrival:  " .  
 "$data_start\n" . 
 "Date of Departure:  " . 
 "$data_end\n" .  
 "\n\n---------------- END OF MESSAGE -----------------\n" ;
mail($mailto, $subject, $messageproper, "From: \"$name\" <$email>\r\nReply-To: \"$name\" <$email>\r\nX-Mailer: chfeedback.php 2.04" );
header( "Location: $thankyouurl" );
 // delete the cookie so it cannot sent again by refreshing this page
 setcookie('tntcon','');  
 exit;
 
 // if verification code was incorrect then return to contact page and show error
 header("location:contact.php?Title=$Title&name=$name&email=$email&phone=$phone&fax=$fax&nationality=$nationality&data_start=$data_start&data_end=$data_end&result=$result&pax=$pax&children=$children&payment=$payment&appick=$appick&purpose=$purpose&comment=$comment&wrong_code=true");
exit;
} else {
 echo "You entered a wrong verification code. Please go back and try again.";
 exit ;
}
?>

# 2  
Old 11-09-2010
maybe try:
Code:
...
} 
$arrive = explode($_POST['$data_start'],"/");
$arrive[2] =yyyy
$arrive[1] =mm
$arrive[0] =dd
// swap round
$data_start = sprintf("%s/%s/%s",$arrive[2],$arrive[1],$arrive[0]);
}
...

# 3  
Old 11-09-2010
@ gc_sw Smilie Thanks for the hint, but you changed only the sequence, right ?

Looking at the code in your post below, which you gave me, you'll see:
$arrive[1] =mm

in black, whereas 0 and 2 are in red !
And so does my phpDesigner 7. It comes up with "syntax error unexpected T_Variable" at that line, which is line 42 in my code.
I can't see what's wrong with that line. Can you ?
# 4  
Old 11-09-2010
i have not changed the sequence. i have assigned inverse order.
Code:
...
} 
$arrive = explode($_POST['$data_start'],"/");
$arrive[0] =dd
$arrive[1] =mm
$arrive[2] =yyyy
// swap round
$data_start = sprintf("%s/%s/%s",$arrive[2],$arrive[1],$arrive[0]);
}
...

# 5  
Old 11-09-2010
OK, if I had put it wrong - that's due to my English -sorry, not my native language. But phpDesigner still comes up with the same error. (the screenshot is attached). Do you have any idea why ?
change date format from yyyy/mm/dd to dd/mm/yyyy-arrivejpg

Last edited by keyboarder; 11-09-2010 at 12:53 PM..
# 6  
Old 11-09-2010
sh... where is that jpg now, which I attached and uploaded ? I tried again to upload, but it says: "You have already attached this file in thread..."

---------- Post updated at 11:05 PM ---------- Previous update was at 10:57 PM ----------

I renamed the jpeg and tried again to upload --> same message "You have already attached this file in thread " ! ?? Anyway...
# 7  
Old 11-10-2010
your picture is here:

Image

well but i'm not sure what error it is.

Last edited by gc_sw; 11-10-2010 at 07:04 AM..

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Date format change from mm/dd/yyyy to yyyymmdd in comma seperate line in perl

Hi All, I have line ,A,FDRM0002,12/21/2017,,0.961751583,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, it contains date in mm/dd/yyyy format i want to change this to yyyymmdd format using perl. Use code tags, thanks. (8 Replies)
Discussion started by: vishal0746
8 Replies

2. Shell Programming and Scripting

Date format YYYY/MM/DD to DD/MM/YYYY

I am getting output of YYYY-MM-DD and want to change this to DD/MM/YYYY. When am running the query in 'Todd' to_date(column_name,'DD/MM/YYYY') am getting the required o/p of DD/MM/YYYY, But when am executing the same query(Netezza) in linux server(bash) am getting the output of YYYY-MM-DD file... (3 Replies)
Discussion started by: Roozo
3 Replies

3. Shell Programming and Scripting

Date Format MM/DD/YYYY

I am changing epoch times to dates. I was able to do the following: echo "$varx" | gawk '{print strftime("%c", $0)}' Mon Dec 31 16:26:40 2012 This changes the epoch date (which is what varx is) into localtime. However, my problem is that I only want 12/31/2012 and not the Mon Dec 31... (2 Replies)
Discussion started by: newbie2010
2 Replies

4. UNIX for Dummies Questions & Answers

Epoch date to YYYY/MM/DD or MM/DD/YYYY

I've seen a lot of posts on this and have tried the following: echo 1257000000| perl -e '($d,$m,$y)=(localtime(time-86400));$m+=1;$y+=1900;printf "$y/$m/$d\n";' But I am unable to convert a past Epoch date into a format such as YYYY/MM/DD or MM/DD/YYYY. I am using bash and don't know... (4 Replies)
Discussion started by: newbie2010
4 Replies

5. Shell Programming and Scripting

need code for date which is in yyyy-mm-dd format

Hi, I am having one log files. contains som data according to date. And it is going to append .Eg:abc.log contains below data 2011-10-19 abjhgj 2011-10-19 gjhgjgj 2011-10-20 hhhjh 2011-10-20 hhhhjj 2011-10-21 gg . . . 2011-11-24 yyy from log files i want catch only... (2 Replies)
Discussion started by: aish11
2 Replies

6. Shell Programming and Scripting

Need date in the format [mm dd yyyy hh AM/PM]

could you please help be on the below code .. Requirement is when i pass the parameter(for below 2) i should get current time -2 hours in the format :wall:.. cur_dt=`$ICEBIN/sqsh -S$DSQUERY -U $BATCHID -P $PASSWD -h -C"select getdate()" | sed '2d'` pr_dt="`$ICEBIN/sqsh -S$DSQUERY -U $BATCHID... (2 Replies)
Discussion started by: karthicss
2 Replies

7. Shell Programming and Scripting

Converting date DD MM YYYY to DD MON YYYY

Hello, I am writing a script that parses different logs and produces one. In the source files, the date is in DD MM YYYY HH24:MI:SS format. In the output, it should be in DD MON YYY HH24:MI:SS (ie 25 Jan 2010 16:10:10) To extract the dates, I am using shell substrings, i.e.: read line ... (4 Replies)
Discussion started by: Adamm
4 Replies

8. UNIX for Dummies Questions & Answers

Format date from MM/DD/YYYY to YYYYMMDD

I have a file with some date columns in MM/DD/YYYY format: SMPBR|DUP-DO NOT USE|NEW YORK||16105|BA5270715|6/6/2007 |MWERNER|109||||JOHN||SMITH|MD|72211118||||||74559|21 WILMINGTON RD||D|11/6/2003|SL# MD CONTACT-LIZ RICHARDS|||0|Y|N||1411458| And I want to convert the date format to: ... (5 Replies)
Discussion started by: ChicagoBlues
5 Replies

9. Shell Programming and Scripting

converting the date field from dd/mm/yyyy to yyyy/mm/dd

How to convert the date field from dd/mm/yyyy to yyyy/mm/dd in unix my script will generate text file which have two fields one is date and another is name of the server for example this is sample date which I have to sort based on older to newer date the problem is when I found out sort will... (4 Replies)
Discussion started by: pareshan
4 Replies

10. Shell Programming and Scripting

Change Date from dd-mmm-yyyy to mm/dd/yyyy

I want to change a date from format dd-mmm-yyyy to mm/dd/yyyy. Is there a way to do this with sed or do you have to write a case statement to convert JAN to 01? Thanks (9 Replies)
Discussion started by: stringzz
9 Replies

Featured Tech Videos