Solved

how to format a date & put in file?

Posted on 2002-04-07
7
239 Views
Last Modified: 2008-03-10
hai,
I have a date format as 27/02/2002 which I need to added to a tmp file & then to mysql db(which accepts only yymmdd format)
my coding as follows

ereg("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})", trim($a[5]),$regs // where $a[5] is an array index which stores the date value.

echo "<td>".$regs[3]."-".$regs[2]."-".$regs[1]."</td>";
$a[5] = $regs[3]."-".$regs[2]."-".$regs[1];//here I change to yymmday format

//if I want to add this in to temp file I add foll code
$writetofile5 = fputs($fd,$a[5].",")); //where $fd is tmp file.

I still cannot get my required format in the temp file.
it still exists as 27/02/2002

can anyone suggest how to write in a file my revised format.
thank u




0
Comment
Question by:manju70
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 5

Accepted Solution

by:
dkjariwala earned 25 total points
ID: 6924764
You can do without regexp here.

Try this.

$org_date = "27/02/2002";

$date_arr = explode("/",$org_date);
//$date_arr[0] = 27
//$date_arr[1] = 02
//$date_arr[2] = 2002

// So now you can construct date in format you like.

$new_date1= $date_arr[2] . "/" . $date_arr[1] . "/" . $date_arr[0]; //YYYY/MM/DD format in $new_date1.

//$new_date1=2002/02/27

$new_date2 = substr($date_arr[2],2). "/" . $date_arr[1] . "/" . $date_arr[0]; //YY/MM/DD format in $new_date2.

$new_date2 = 02/02/27


Hope that helps,
JD


0
 

Author Comment

by:manju70
ID: 6924792
hai JD,

thanks for ur reply.
but can u tell me how to add it in a tmp file using fputs function.

my coding for the same is as below.

$writetofile5 = fputs($fd,$new_date2.",")); //where $fd is tmp file.

can u check for me.

thanks




 

0
 
LVL 5

Expert Comment

by:dkjariwala
ID: 6924797
Yeah that code is correct.

Provided you have *successfully* opened file having pointer $fd.

JD
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

Author Comment

by:manju70
ID: 6924929
thank u JD,

It works well.
thank u very much.

c u then if I have any more queries.
bye


0
 
LVL 5

Expert Comment

by:dkjariwala
ID: 6924940
Sure.

Manju, are you indian by any chance ??

JD
0
 

Author Comment

by:manju70
ID: 6927401
yes why????????
0
 

Author Comment

by:manju70
ID: 6927404
yes why????????
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question