Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display World Wide Web Consortium time/date in XML file 1

Status
Not open for further replies.

Smoothas

IS-IT--Management
May 1, 2002
93
GB
Hello,

I'm trying to display World Wide Web Consortium time and date into an xml file.
I've been trying mktime() and getdate(), but I'm not getting the format i require :-

2009-10-01T16:16:59.0156250+01:00

Can anyone help ?

Thanks
 
Hi

To me that looks like ISO 8601, which is returned by [tt]date('c')[/tt]. Unless fractions of seconds are meaningful for you. In which case I am afraid, you will have to format is "manually" as [tt]date('Y-m-d\TH:i:s.uP')[/tt].

Or I misunderstood your question.

Feherke.
 
Hello,
Thanks for your help,

I've tried what you said but I get " c " come out instead.

I'm trying to assign it to a variable :_

$CrqDateTime = date('c');

and then call it up later when writing to a file

$xml_document .= $CrqDateTime;

Am I also planning on using it as part of the file name

$path_dir .= $urlDoc . $CrqDateTime . ".xml";
 
Hi

Smoothas said:
I've tried what you said but I get " c " come out instead.
Then your PHP version is older than 5. Use the second way.

Note that the [tt]date()[/tt] function as mentioned in my previous post will format the current time. Anyway, you wrote nothing about what are you trying to format...

Feherke.
 
Hi Feherke,

I tried it the second way but still get a little c as the output.

I'm just trying to past the date/time etc in the format i mentioned in my original post.
The XML file i'm trying to create needs the date in this particaulr formated when past to another system.

Thanks again
 
Hi

Smoothas said:
I tried it the second way but still get a little c as the output.
You either not used the second [tt]date()[/tt] call I posted or not like this :
Code:
$CrqDateTime = date('Y-m-d\TH:i:s.uP');
But there is no way the above to output "c".

Feherke.
 
HI,

I cut'n'pasted the above line into my php codeing and got the following output when viewing the created file :-

<CrqDateTime>c</CrqDateTime>

What could be going wrong then if you code cannot produce a c as output? Could my ISP have a version of PHP even older than 5 ?

Thanks again
 
that way works in older versions of php

Code:
cat date.php
<?php
echo date('Y-m-d\TH:i:s.uP');
?>
[user@server php]# php date.php
X-Powered-By: PHP/4.4.6
Content-type: text/html

2009-10-01T14:05:47.uP

-----------------------------------------
I cannot be bought. Find leasing information at
 
OK, so whhy would assigning it to a variable produce c as an output instead of your results ?
 
I've seen what i've done, ther were t Date varables ( one was in the "old" format, the other in the new one ) and one was counteracting the other.

Thanks, the date ect comes out as you have showen.

How can I get it looking like :-

2009-10-01T16:16:59.0156250+01:00

instead of the "uP" at the end ?

thanks again
 
Hi

Smoothas said:
How can I get it looking like :-

2009-10-01T16:16:59.0156250+01:00

instead of the "uP" at the end ?
While the [tt]u[/tt] and [tt]P[/tt] format strings require even newer PHP version then [tt]c[/tt], your only way would be a workaround :
Code:
[navy]$CrqDateTime[/navy][teal]=[/teal][COLOR=darkgoldenrod]str_replace[/color][teal]([/teal][green][i]'%'[/i][/green][teal],[/teal][COLOR=darkgoldenrod]substr[/color][teal]([/teal][COLOR=darkgoldenrod]microtime[/color][teal](),[/teal][purple]2[/purple][teal],[/teal][purple]7[/purple][teal]),[/teal][COLOR=darkgoldenrod]date[/color][teal]([/teal][green][i]'Y-m-d\TH:i:s.%O'[/i][/green][teal]));[/teal]
[navy]$CrqDateTime[/navy][teal]=[/teal][COLOR=darkgoldenrod]substr[/color][teal]([/teal][navy]$CrqDateTime[/navy][teal],[/teal][purple]0[/purple][teal],-[/teal][purple]2[/purple][teal]).[/teal][green][i]':'[/i][/green][teal].[/teal][COLOR=darkgoldenrod]substr[/color][teal]([/teal][navy]$CrqDateTime[/navy][teal],-[/teal][purple]2[/purple][teal]);[/teal]
But personally I would just use [tt]date('Y-m-d\TH:i:s')[/tt].


Feherke.
 
Hi,

Thank last code woeked like a charm.

Many Thanks to everyone for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top