Solved

how to format a date & put in file?

Posted on 2002-04-07
7
232 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
  • 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP query / monitor data from Telnet to MySQL 7 51
How do I fix this UPDATE error? 7 32
php help 34 58
MVC - procedural PHP 10 38
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

827 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