Page 1 of 1

Php Date

Posted: Tue May 08, 2007 6:10 pm
by l9pt5
I've the following code, but I want to insert some spaces or some characters between the date and the time (betwwen the letter Y and letter g below), how do I do that? I tried with the space but it doesn't work.

Code: Select all

date("n/d/Y  g:i a", $somedate)

Posted: Tue May 08, 2007 6:23 pm
by Begby
Are you trying to use more than one space? Does one space work?

Posted: Tue May 08, 2007 6:24 pm
by l9pt5
Yes, I'm trying to use more than one space.

Posted: Tue May 08, 2007 7:09 pm
by feyd
Either add escaped characters into the format string or create the date component, add your additional text, then the time component. I can only assume you're attempting to see this in a browser, in which case you will need   for additional spaces beyond one.

Posted: Wed May 09, 2007 10:41 am
by l9pt5
ok, I tried the escaped characters for the spaces in the code below

Code: Select all

echo date("m/d/Y \s\s\s\s g:i:s a", mktime());
and I get the following ssss instead of spaces.

05/09/2007 ssss 11:39:51 am

Posted: Wed May 09, 2007 11:12 am
by aaronhall
Are you printing the returned string in an HTML document? If so, read feyd's post

Posted: Wed May 09, 2007 11:18 am
by l9pt5
I want to use the escaped character in the string instead of create a date component and a time component. Am I not using the escaped character correctly?

Posted: Wed May 09, 2007 11:43 am
by aaronhall
HTML or not?

Posted: Wed May 09, 2007 12:04 pm
by l9pt5
sorry, HTML document.

Posted: Wed May 09, 2007 12:24 pm
by aaronhall
As feyd touched on, your browser will render two or more consecutive spaces as one, and the only way to override that is to replace the additional spaces with the escape sequence:  

If you stick that straight into the date() call, you'll have to escape at least a few of those letters lest date() tries to interpret them. date()'s special characters are listed in the manual entry (date()); all are escaped with a backslash.

Posted: Wed May 09, 2007 12:34 pm
by aaronhall
You can also wrap the date and its surrounding content in <pre></pre>, depending on your situation.

Posted: Wed May 09, 2007 2:41 pm
by l9pt5
Phewwwwwww, got it to work with the following code. What threwing me off was the letter 'n', I've to use \\

Thanks for the advice everyone.

Code: Select all

echo date("m/d/Y \&\\n\b\s\p\; \&\\n\b\s\p\; \&\\n\b\s\p\; \&\\n\b\s\p\;  g:i:s a", mktime());