[PHP] Date formatting issue

2008-08-05 Thread Don Don
Hi all,

I've got dates in the following formats e.g.

August 05, 2008, 10:14 am (e.g. today's date)
August 04, 2008, 7:08 am (e.g. yesterda's date)
August 03, 2008, 9:08 am (e.g. in the past)

I am trying to format these dates do I can display them like this

Today at 10:14 am (today)
Yesterday at 9:08 am (yesterday)
August 03, 9:08 am (if its not today or yesterday then display the month and 
day and time only)

Can anyone help with tips on how to achieve this ?

Cheers




  

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Date formatting issue

2008-08-05 Thread Dan Joseph
On Tue, Aug 5, 2008 at 11:48 AM, Don Don [EMAIL PROTECTED] wrote:

 Hi all,

 I've got dates in the following formats e.g.

 August 05, 2008, 10:14 am (e.g. today's date)
 August 04, 2008, 7:08 am (e.g. yesterda's date)
 August 03, 2008, 9:08 am (e.g. in the past)

 I am trying to format these dates do I can display them like this

 Today at 10:14 am (today)
 Yesterday at 9:08 am (yesterday)
 August 03, 9:08 am (if its not today or yesterday then display the month
 and day and time only)

 Can anyone help with tips on how to achieve this ?

 Cheers






 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


Check out date() and mktime() -- http://www.php.net/date
http://www.php.net/mktime

Both of those should get you in the direction of formating dates.

-- 
-Dan Joseph

www.canishosting.com - Plans start @ $1.99/month.

Build a man a fire, and he will be warm for the rest of the day.
Light a man on fire, and will be warm for the rest of his life.


Re: [PHP] Date formatting issue

2008-08-05 Thread Daniel Brown
On Tue, Aug 5, 2008 at 11:48 AM, Don Don [EMAIL PROTECTED] wrote:
 Hi all,

 I've got dates in the following formats e.g.

 August 05, 2008, 10:14 am (e.g. today's date)
 August 04, 2008, 7:08 am (e.g. yesterda's date)
 August 03, 2008, 9:08 am (e.g. in the past)

 I am trying to format these dates do I can display them like this

 Today at 10:14 am (today)
 Yesterday at 9:08 am (yesterday)
 August 03, 9:08 am (if its not today or yesterday then display the month and 
 day and time only)

If $month equals date(m) and $year equals date(Y) and $day
equals date(d) - 1 then it's yesterday.

If $month equals date(m) and $year equals date(Y) and $day
equals date(d) then it's today.

If $month equals date(m) and $year equals date(Y) and $day
equals date(d) + 1 then it's tomorrow.

Otherwise, echo date(F d, g:i a);


As Dan Joseph mentioned, read up on date()[1] and mktime()[2], and
I'd also recommend strtotime()[3].  Moreover, take the logic above and
code your PHP to match it. A simple if/elseif/else or case/switch
block will do it for you.



1:  http://php.net/date
2:  http://php.net/mktime
3:  http://php.net/strtotime

-- 
/Daniel P. Brown
More full-root dedicated server packages:
Intel 2.4GHz/60GB/512MB/2TB $49.99/mo.
Intel 3.06GHz/80GB/1GB/2TB $59.99/mo.
Intel 2.4GHz/320/GB/1GB/3TB $74.99/mo.
Dedicated servers, VPS, and hosting from $2.50/mo.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] date formatting

2007-08-29 Thread Mike Ryan
I would like to have my users input the date formate as mm-dd- mysql
wants the data to come down as -mm-dd.

The question I have is how do I convert from the mm-dd- to -mm-dd so
that I can write it out to the database?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date formatting

2007-08-29 Thread Wolf
Just have your input form get it in sections, then piece it all together when 
dumping it to MySQL

This way you can transparent the code on the front to users, but have it in the 
right format in the backend.

 Mike Ryan [EMAIL PROTECTED] wrote: 
 I would like to have my users input the date formate as mm-dd- mysql
 wants the data to come down as -mm-dd.
 
 The question I have is how do I convert from the mm-dd- to -mm-dd so
 that I can write it out to the database?
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] date formatting

2007-08-29 Thread Richard Lynch


On Wed, August 29, 2007 4:12 pm, Mike Ryan wrote:
 I would like to have my users input the date formate as mm-dd-
 mysql
 wants the data to come down as -mm-dd.

 The question I have is how do I convert from the mm-dd- to
 -mm-dd so
 that I can write it out to the database?

You could tell MySQL to use the mm-dd- input format I think.  Ask
on a mysql list.

In PHP:

?php
  if (preg_match('|([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})|', $date,
$parts){
$m = $parts[1];
$d = $parts[2];
$y = $parts[3];
$date_sql = mysql_real_escape_string($y-$m-$d));
  }
  else die(Invalid date input.);
?

die() is probably a bit extreme for this, but it's a start.

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Please vote for this great band:
http://acl.mp3.com/feature/soundandjury/?band=COMPANY-OF-THIEVES

Requires email confirmation.
One vote per day per email limit.
Obvious ballot-stuffing will be revoked.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] date formatting - no question here just a tip ...

2006-12-14 Thread Jochem Maas
have you ever had the need to programmatically convert a date()
compatible date formatting string with one compatible for strftime()?

I had this problem recently when I had to l10n an existing app (and
support legacy data - which include date() formatting strings - at the
same time) ... I came up with this (it's not very exciting but it might save
someone the rather mindnumbing job of trying to correlate the date()
and strftime() formatting codes - also note that the correlation is not 100%,
in cases where I couldn't find a real/proper match I just did what I thought
was best - which sometimes meant leaving the replacement blank):

function getSTFDateFormat($fmt)
{
static $dfMap = array(
'd' = '%d', // Day of the month, 2 digits with leading zeros   
01 to 31
'D' = '%a', // A textual representation of a day, three letters
Mon through Sun
'j' = '%e', // Day of the month without leading zeros  1 to 31
'l' = '%A', // A full textual representation of the day of the week
Sunday through Saturday
'N' = '%u', // ISO-8601 numeric representation of the day of the 
week (added in PHP 5.1.0) 1 (for Monday)
through 7 (for Sunday)
'S' = '',   // English ordinal suffix for the day of the month, 2 
characters   st, nd, rd or th. Works well with j
'w' = '%w', // Numeric representation of the day of the week   
0 (for Sunday) through 6 (for Saturday)
'z' = '%j', // The day of the year (starting from 0)   0 
through 365
'W' = '%V', // ISO-8601 week number of year, weeks starting on 
Monday (added in PHP 4.1.0) Example: 42 (the
42nd week in the year)
'F' = '%B', // A full textual representation of a month, such as 
January or March  January through December
'm' = '%m', // Numeric representation of a month, with leading 
zeros   01 through 12
'M' = '%b', // A short textual representation of a month, three 
lettersJan through Dec
'n' = '%m', // Numeric representation of a month, without leading 
zeros1 through 12
't' = '',   // Number of days in the given month   28 through 31
'L' = '',   // Whether it's a leap year1 if it is a leap year, 
0 otherwise.
'o' = '%G', // ISO-8601 year number. This has the same value as Y, 
except that if the ISO week number (W)
belongs to the previous or next year, that year is used instead. (added in PHP 
5.1.0)   Examples: 1999 or 2003
'Y' = '%Y', // A full numeric representation of a year, 4 digits   
Examples: 1999 or 2003
'y' = '%y', // A two digit representation of a year
Examples: 99 or 03
'a' = '%p', // Lowercase Ante meridiem and Post meridiem   am or pm
'A' = '%p', // Uppercase Ante meridiem and Post meridiem   AM or PM
'B' = '',   // Swatch Internet time000 through 999
'g' = '%I', // 12-hour format of an hour without leading zeros 
1 through 12
'G' = '%H', // 24-hour format of an hour without leading zeros 
0 through 23
'h' = '%I', // 12-hour format of an hour with leading zeros
01 through 12
'H' = '%H', // 24-hour format of an hour with leading zeros
00 through 23
'i' = '%M', // Minutes with leading zeros  00 to 59
's' = '%S', // Seconds, with leading zeros 00 through 59
'e' = '%Z', // Timezone identifier (added in PHP 5.1.0)
Examples: UTC, GMT, Atlantic/Azores
'I' = '',   // Whether or not the date is in daylight saving time  
1 if Daylight Saving Time, 0 otherwise.
'O' = '',   // Difference to Greenwich time (GMT) in hours 
Example: +0200
'P' = '',   // Difference to Greenwich time (GMT) with colon 
between hours and minutes (added in PHP 5.1.3)
Example: +02:00
'T' = '%z', // Timezone setting of this machineExamples: EST, 
MDT ...
'Z' = '',   // Timezone offset in seconds. The offset for 
timezones west of UTC is always negative, and for
those east of UTC is always positive.   -43200 through 50400
'c' = '%c', // ISO 8601 date (added in PHP 5)  
2004-02-12T15:19:21+00:00
'r' = '%a, %m %b %Y %T', // RFC 2822 formatted date
Example: Thu, 21 Dec 2000 16:01:07 +0200
'U' = '', // Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
);

if (strpos($fmt, '%') === false) {
$find = array_keys($dfMap);
foreach ($find as $k = $v) {
$find[$k] = '#(?!%)'.$v.'#'; // negative lookbehind assertion 
(must not be preceeded by a % sign)
}
// try to convert date() format to strftime() format
$fmt = preg_replace($find, array_values($dfMap), $fmt);
}

return $fmt;
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Date Formatting

2002-12-13 Thread Clint Tredway
How can I format a date coming out of a MySQL? I know how to format today's date but 
not a date coming out of MySQL. I have looked through the manual, but I must be blind 
because I cannot figure it out.

Thanks,
Clint


Re: [PHP] Date Formatting

2002-12-13 Thread Support @ Fourthrealm.com
Use this:
function makedate($format, $indate)
{
$temp = explode(-, $indate);
$fulldate = mktime(0, 0, 0, $temp[1], $temp[2], $temp[0]);
$temp = date($format, $fulldate);
return ($temp);
}

and call it with this:
makedate(F d, Y, $row-datefield);

where $row-datefield is the variable of the date field in your table.


Peter


At 11:55 AM 12/13/2002 -0600, you wrote:

How can I format a date coming out of a MySQL? I know how to format 
today's date but not a date coming out of MySQL. I have looked through the 
manual, but I must be blind because I cannot figure it out.

Thanks,
Clint

- - - - - - - - - - - - - - - - - - - - -
Fourth Realm Solutions
[EMAIL PROTECTED]
http://www.fourthrealm.com
Tel: 519-739-1652
- - - - - - - - - - - - - - - - - - - - -


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Date Formatting

2002-12-13 Thread Joseph W. Goff
Just a small question, but why not just do this through the SQL statement
instead of using php?
http://www.mysql.com/doc/en/Date_and_time_functions.html#IDX1295
[from the mysql manual]
mysql SELECT DATE_FORMAT('1997-10-04 22:23:00', '%W %M %Y');
- 'Saturday October 1997'
mysql SELECT DATE_FORMAT('1997-10-04 22:23:00', '%H:%i:%s');
- '22:23:00'
mysql SELECT DATE_FORMAT('1997-10-04 22:23:00',
  '%D %y %a %d %m %b %j');
- '4th 97 Sat 04 10 Oct 277'

- Original Message -
From: Clint Tredway [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, December 13, 2002 11:55 AM
Subject: [PHP] Date Formatting


How can I format a date coming out of a MySQL? I know how to format today's
date but not a date coming out of MySQL. I have looked through the manual,
but I must be blind because I cannot figure it out.

Thanks,
Clint


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Date Formatting

2002-12-13 Thread 1LT John W. Holmes
Use DATE_FORMAT() in your query, or UNIX_TIMESTAMP() to pull it out as a
unix timestamp and use date() in PHP to format it.

Chapter 6, Date and Time Functions in the MySQL Manual has the syntax for
each of the MySQL functions.

---John Holmes...

- Original Message -
From: Clint Tredway [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, December 13, 2002 12:55 PM
Subject: [PHP] Date Formatting


How can I format a date coming out of a MySQL? I know how to format today's
date but not a date coming out of MySQL. I have looked through the manual,
but I must be blind because I cannot figure it out.

Thanks,
Clint


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Date Formatting

2002-12-13 Thread Rick Emery
MYSQL will do all the formatting that you need.  Look up sect 6.3.4, Date and Time
Functions in mysql manual.  Look at the DATE_FORMAT(date,format) command

- Original Message -
From: Clint Tredway [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, December 13, 2002 11:55 AM
Subject: [PHP] Date Formatting


How can I format a date coming out of a MySQL? I know how to format today's date but 
not a
date coming out of MySQL. I have looked through the manual, but I must be blind 
because I
cannot figure it out.

Thanks,
Clint


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Date Formatting

2002-12-13 Thread Clint Tredway
thanks for all the replies. I was able to use the date_format() from MySQL.

Clint

- Original Message -
From: Rick Emery [EMAIL PROTECTED]
To: Clint Tredway [EMAIL PROTECTED];
[EMAIL PROTECTED]
Sent: Friday, December 13, 2002 1:13 PM
Subject: Re: [PHP] Date Formatting


 MYSQL will do all the formatting that you need.  Look up sect 6.3.4, Date
and Time
 Functions in mysql manual.  Look at the DATE_FORMAT(date,format) command

 - Original Message -
 From: Clint Tredway [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Friday, December 13, 2002 11:55 AM
 Subject: [PHP] Date Formatting


 How can I format a date coming out of a MySQL? I know how to format
today's date but not a
 date coming out of MySQL. I have looked through the manual, but I must be
blind because I
 cannot figure it out.

 Thanks,
 Clint


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Date formatting from a mySQL timestamp

2002-10-16 Thread Ricardo Fitzgerald

Hi,

I have the following query :
for($i = 0; $i =$num_results; $i++)
{
$row = mysql_fetch_object($result);
echo table width =\100%\ border =\0\ cellpadding = \3\\n
   .tr\n
   .td bgcolor = \#ee\ align = \left\$row-id/td\n
   .td bgcolor = \#ee\ align = \left\$row-Nombre/td\n
   .td bgcolor = \#ee\ align = \left\$row-Apellido/td\n
   .td bgcolor = \#ee\ align = \left\$row-Direccion/td\n
   .td bgcolor = \#ee\ align = \left\$row-Ciudad/td\n
   .td bgcolor = \#ee\ align = \left\$row-Telefono/td\n
   .td bgcolor = \#ee\ align = \left\$row-Mail/td\n
   .td bgcolor = \#ee\ align = \left\$row-Pais/td\n
   .td bgcolor = \#ee\ align = \left\.date(r,
$row-date).td\n
// My problem is it's getting the wrong date no matter what I do, every line
displays Jan 2038 !!!
   ./tr\n
   ./table\n;
If I try another strings i got errors the row $date is in MYSQL unix
timestamp. and i would like to format it.
BTW I would like a better alignment and format also ...

TIA

Regards,

Rick


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Date formatting from a mySQL timestamp

2002-10-16 Thread 1LT John W. Holmes

 I have the following query :
 for($i = 0; $i =$num_results; $i++)
 {
 $row = mysql_fetch_object($result);
 echo table width =\100%\ border =\0\ cellpadding = \3\\n
.tr\n

You can save some typing if you just set the bgcolor in the tr, instead of
each td, FYI. Also, align defaults to left, doesn't it? So you can
probably leave that out, also.

.td bgcolor = \#ee\ align = \left\$row-id/td\n
.td bgcolor = \#ee\ align = \left\$row-Nombre/td\n
.td bgcolor = \#ee\ align = \left\$row-Apellido/td\n
.td bgcolor = \#ee\ align =
\left\$row-Direccion/td\n
.td bgcolor = \#ee\ align = \left\$row-Ciudad/td\n
.td bgcolor = \#ee\ align = \left\$row-Telefono/td\n
.td bgcolor = \#ee\ align = \left\$row-Mail/td\n
.td bgcolor = \#ee\ align = \left\$row-Pais/td\n
.td bgcolor = \#ee\ align = \left\.date(r,
 $row-date).td\n
 // My problem is it's getting the wrong date no matter what I do, every
line
 displays Jan 2038 !!!

I think you're confused here. MySQL uses a different style timestamp than a
Unix timestamp. Unix timestamps are the number of seconds since Jan 01,
1970. MySQL timestamps are in a MMDDHHMMSS format. If you've used a
TIMESTAMP, DATE, or DATETIME column in MySQL, then you have a MySQL
timestamp. The MySQL timestamp is not compatible with the PHP date()
function, it is expecting a Unix timestamp.

So...the solution is one of two things. You can use an INT column and store
the unix timestamp into it. You can create the unix timstamp in PHP with
time(), mktime(), or strtotime() (among others), and format it with the
date() function. Or, you can continue to use a MySQL type timestamp and use
the MySQL function DATE_FORMAT() to format the dates _in your query_.
DATE_FORMAT() is the MySQL equivilent of PHP's date() function. Or, as a
third option, you can use the MySQL UNIX_TIMESTAMP() function to create a
Unix timestamp from the MySQL timestamp and return that to PHP. You can then
use that in  your date() function.

Confusing, eh? If you have any questions, I can explain it further.

---John Holmes...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Date formatting

2002-07-10 Thread Rw

Had trouble getting this posed at the newsgroup - will try on the maillist
here:

I have a date field passed in a form like this:

01-02-2003

Is there a handy function to convert that to other ways of expressing the
date such as:

01/02/03

OR

2003-01-02

I know the syntax of the date formatting expressions ... just not for the
converting.

Thanks!



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Date formatting

2002-07-10 Thread Dan Vande More

To convert from user format to mysql I use:

$training_date=$_POST[training_date];
$training_date=str_replace(-, /, $training_date);//strtotime doesnt seem to work 
right if it has 12-25-2002, but does if it has 12/25/2002
$training_date=strtotime($training_date);
$training_date=date(Y-m-d,$training_date);

To convert from mysql to user I do:

$field_hire_date=$row_current_emps['field_hire_date']; 
$field_hire_date=strtotime($field_hire_date);
$field_hire_date=date(m/d/Y , $field_hire_date);



-Original Message-
From: Rw [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 10, 2002 11:25 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Date formatting


Had trouble getting this posed at the newsgroup - will try on the maillist
here:

I have a date field passed in a form like this:

01-02-2003

Is there a handy function to convert that to other ways of expressing the
date such as:

01/02/03

OR

2003-01-02

I know the syntax of the date formatting expressions ... just not for the
converting.

Thanks!



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Date formatting

2002-07-10 Thread Analysis Solutions

On Wed, Jul 10, 2002 at 12:25:08PM -0500, Rw wrote:
 
 01-02-2003
 
 Is there a handy function to convert that to other ways of expressing the
 date such as:
 
 01/02/03

$temp = preg_replace('/^(\d{2})-(\d{2})-(\d{2})(\d{2})$/', '\\1/\\2/\\4',
  $date);


 2003-01-02

$temp = preg_replace('/^(\d{2})-(\d{2})-(\d{4})$/', '\\3/\\1/\\2',
  $date);

It's also a good idea to do a test to make sure the initial date is in the 
format you expect it to be:

if ($temp == $date) {
   echo 'WAIT a second...  Your initial date was bad.';
}

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Date Formatting/Reading

2001-12-13 Thread PHPGalaxy.com

Hi! =)

I'm doing a website that will be using a pay-per-month membership
program. There's a field for 'lastpaid' that holds the date the last
paid (sorry to state the obvious). My questions are these:
1) What would be the best way to format it so PHP can see if it's been
30 days since it was last paid?
2) What line of code would be used to check?
3) Would I set the field type to DATE, DATETIME, TIMESTAMP or soemthing
else?

Any help you can give would be much appreciated! I woulda taken the time
to study it more in-depth but I'm trying to get as much done on this in
5 hours as I can. =)

 ~ Tim

--
From PHPGalaxy.com, earn up to $10 per order selling our PHP Scripts
and Software on your Site. http://www.phpgalaxy.com/aff/

Also, get a fast free POP3 email account, you @php.la at
http://www.phpgalaxy.com/search/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Date formatting

2001-12-11 Thread phantom

What would be an easy what to format a date value into month day year??
I want to specially display a date stored in mysql in date format
-MM-DD

The manual says: string date (string format, int [timestamp])

I tried $FormattedDate = date(F y, Y,${StoredDate})

1999-04-15 spit out December 31, 1969 when I had hoped for April 15,
1999.

Apparently -MM-DD is not a valid timestamp... i tried mysql formats
of timestamp(8) and timestamp(14) and that didn't work either




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Date formatting

2001-12-11 Thread Kevin Stone

Try using the DATE_FORMAT() function within your SQL query string...

$query = SELELCT DATE_FORMAT (your_date_column, '%M %d %Y') FROM
your_table;

where:
%M is the month in full text
%d is the numerical day of the month with leading zeros
%Y is the four digit year

Extract the results as ussual... mysql_fetch_row() or mysql_fetch_array() or
whatever you would use.  Let me know if this works becuase I've not tried it
before.  Seems like it should work though.  Good luck.  :-)

-Kevin Stone

- Original Message -
From: phantom [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, December 10, 2001 8:35 PM
Subject: [PHP] Date formatting


 What would be an easy what to format a date value into month day year??
 I want to specially display a date stored in mysql in date format
 -MM-DD

 The manual says: string date (string format, int [timestamp])

 I tried $FormattedDate = date(F y, Y,${StoredDate})

 1999-04-15 spit out December 31, 1969 when I had hoped for April 15,
 1999.

 Apparently -MM-DD is not a valid timestamp... i tried mysql formats
 of timestamp(8) and timestamp(14) and that didn't work either




 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Date formatting

2001-12-11 Thread Steve Cayford


On Monday, December 10, 2001, at 09:35  PM, phantom wrote:

 What would be an easy what to format a date value into month day year??
 I want to specially display a date stored in mysql in date format
 -MM-DD

 The manual says: string date (string format, int [timestamp])

 I tried $FormattedDate = date(F y, Y,${StoredDate})


try $FormattedDate = date(F y, Y,strtotime($StoredDate));

strtotime will convert your -MM-DD string into a unix timestamp.

 1999-04-15 spit out December 31, 1969 when I had hoped for April 15,
 1999.

 Apparently -MM-DD is not a valid timestamp... i tried mysql formats
 of timestamp(8) and timestamp(14) and that didn't work either




 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Date formatting

2001-12-11 Thread Miles Thompson

Here, play with this. dtAuctionStart is a MySQL date field, so substitute 
your own connection and var.
Have fun - Miles Thompson

Some messing about with dates br
=br

?
echo $dtAuctionStart, br;
echo date (Y-m-d, $dtAuctionStart ), br;
//$strDate =  $dtAuctionStart ;
echo dtAuctionStart  : $dtAuctionStart;

$year = substr ($dtAuctionStart, 0, 4);
$month =substr( $dtAuctionStart, 4, 2 );
$day =  substr ($dtAuctionStart, 6, 2 );
Echo dtAuctionStart in m-d -y : $month-$day-$year br;

$workdate = getdate( $dtAuctionStart );
echo  Workdate Year:, $workdate[year],br;
?

Ereg Stuff br
==br
?
if (ereg (([0-9]{4})([0-9]{1,2})([0-9]{1,2}), $dtAuctionStart, $regs))
{
 echo Auction Start:  $regs[1]-$regs[2]-$regs[3] brbr;
}
else
{
 echo Bad date format. br;
}

//echo gmdate (Y-m-d, time()), br;
echo date (M-d-Y, mktime (0,0,0, $month, $day, $year));
// echo date (M-d-Y, mktime (0,0,0,12,32,1997));


echo brLocal date: br  ;
echo date (M d Y H:i:s, time()), br;
echo date (M d Y H:i:s, time()), br;
echo Greenwich date: br;
echo gmdate (M d Y H:i:s, time()), br;
echo gmdate (YmdHis, time()), br;

?

At 09:35 PM 12/10/2001 -0600, phantom wrote:
What would be an easy what to format a date value into month day year??
I want to specially display a date stored in mysql in date format
-MM-DD

The manual says: string date (string format, int [timestamp])

I tried $FormattedDate = date(F y, Y,${StoredDate})

1999-04-15 spit out December 31, 1969 when I had hoped for April 15,
1999.

Apparently -MM-DD is not a valid timestamp... i tried mysql formats
of timestamp(8) and timestamp(14) and that didn't work either




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Date formatting in PHP 3.0

2001-08-30 Thread Paul McGee

I'm looping through a MSQL db pulling out the dates where I would like to
display the date and then the day of the week.  The problem is that every
date returns the same day of the week, Wed. I checked the documentation and
it doesn't say anything about the expression only being executed once during
inside the WHILE loop.

I've tried:

$m = substr($row[0],0,4);
$d = substr($row[0],5,2);
$y = substr($row[0],8,2);
$dy = date (D, mktime(0,0,0,$m,$d,$y));

and just using the date field

$dy = date (D, $row[0]);

Any help would be greatly appreciated!



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Date formatting in PHP 3.0

2001-08-30 Thread * RzE:

Original message
From: Paul McGee [EMAIL PROTECTED]
Date: Thu, Aug 30, 2001 at 12:13:21PM -0400
Message-ID: [EMAIL PROTECTED]
Subject: [PHP] Date formatting in PHP 3.0

 I'm looping through a MSQL db pulling out the dates where I would like to
 display the date and then the day of the week.  The problem is that every
 date returns the same day of the week, Wed. I checked the documentation and
 it doesn't say anything about the expression only being executed once during
 inside the WHILE loop.
 
 I've tried:
 
 $m = substr($row[0],0,4);
 $d = substr($row[0],5,2);
 $y = substr($row[0],8,2);
 $dy = date (D, mktime(0,0,0,$m,$d,$y));
 
 and just using the date field
 
 $dy = date (D, $row[0]);
 
 Any help would be greatly appreciated!

/Original message

Reply

Did you give a look at your own code?
A month consisting of 4 digits?
And a year consisting of 2 digits?
I'd say:

--- PHP code ---
$y = substr($row[0],0,4);
$m = substr($row[0],5,2);
$d = substr($row[0],8,2);
$dy = date (D, mktime(0,0,0,$m,$d,$y));

and just using the date field

$dy = date (D, $row[0]);
--- End of PHP code ---

/Reply

-- 

* RzE:

/Reply

-- 

* RzE:


-- 
-- Renze Munnik
-- DataLink BV
--
-- E: [EMAIL PROTECTED]
-- W: +31 23 5326162
-- F: +31 23 5322144
-- M: +31 6 21811143
--
-- Stationsplein 82
-- 2011 LM  HAARLEM
-- Netherlands
--
-- http://www.datalink.nl
-- 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Date formatting in PHP 3.0

2001-08-30 Thread Paul McGee

Thanks, I knew it was something stupid!

However, the $dy = date (D, $row[0]) doesn't work.

* RZe: [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Original message
 From: Paul McGee [EMAIL PROTECTED]
 Date: Thu, Aug 30, 2001 at 12:13:21PM -0400
 Message-ID: [EMAIL PROTECTED]
 Subject: [PHP] Date formatting in PHP 3.0

  I'm looping through a MSQL db pulling out the dates where I would like
to
  display the date and then the day of the week.  The problem is that
every
  date returns the same day of the week, Wed. I checked the documentation
and
  it doesn't say anything about the expression only being executed once
during
  inside the WHILE loop.
 
  I've tried:
 
  $m = substr($row[0],0,4);
  $d = substr($row[0],5,2);
  $y = substr($row[0],8,2);
  $dy = date (D, mktime(0,0,0,$m,$d,$y));
 
  and just using the date field
 
  $dy = date (D, $row[0]);
 
  Any help would be greatly appreciated!

 /Original message

 Reply

 Did you give a look at your own code?
 A month consisting of 4 digits?
 And a year consisting of 2 digits?
 I'd say:

 --- PHP code ---
 $y = substr($row[0],0,4);
 $m = substr($row[0],5,2);
 $d = substr($row[0],8,2);
 $dy = date (D, mktime(0,0,0,$m,$d,$y));

 and just using the date field

 $dy = date (D, $row[0]);
 --- End of PHP code ---

 /Reply

 --

 * RzE:

 /Reply

 --

 * RzE:


 -- 
 -- Renze Munnik
 -- DataLink BV
 --
 -- E: [EMAIL PROTECTED]
 -- W: +31 23 5326162
 -- F: +31 23 5322144
 -- M: +31 6 21811143
 --
 -- Stationsplein 82
 -- 2011 LM  HAARLEM
 -- Netherlands
 --
 -- http://www.datalink.nl
 -- 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Date formatting in PHP 3.0

2001-08-30 Thread * RzE:

Original message
From: Paul McGee [EMAIL PROTECTED]
Date: Thu, Aug 30, 2001 at 12:45:49PM -0400
Message-ID: [EMAIL PROTECTED]
Subject: Re: [PHP] Date formatting in PHP 3.0

 Thanks, I knew it was something stupid!

 However, the $dy = date (D, $row[0]) doesn't work.

/Original message

Reply

You're welcome...

and eh... for the However, the $dy = date (D, $row[0]) doesn't
work.:

It shouldn't. date() requires a timestamp as a second argument, not
a string. Unless you retrieve an actual timestamp from your db
(which you don't) you could directly feed it to date(). So as long
as you get strings from your db you'll have to parse 'm first and
then put them through mktime() (like you do in your example). Then
you have a real timestamp and you can put that through date().

/Reply

-- 

* RzE:


-- 
-- Renze Munnik
-- DataLink BV
--
-- E: [EMAIL PROTECTED]
-- W: +31 23 5326162
-- F: +31 23 5322144
-- M: +31 6 21811143
--
-- Stationsplein 82
-- 2011 LM  HAARLEM
-- Netherlands
--
-- http://www.datalink.nl
-- 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Date formatting

2001-04-06 Thread Matt Davis

Hi I am trying to format a date extracted from my DB. I have run my query
and then have used the following to get my row data

  while ($row = mysql_fetch_array($sql_result)) {
 $title = $row["message_title"];
 $message = $row["message"];
 $event = $row["date_of_event"];

 $shortevent = date ("D j M", $event);

I am trying to take $event and make it diplay like this "FRI 06 APR" using
the date function. Although $event outputs like this "2001-04-06 00:00:00"
$shortevent outputs "Thu 1 Jan" which is unix epoch date.

Does anybody know what I am doiing wrong its probably something really
simple but I cant see what.

Matt.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Date formatting

2001-04-06 Thread Joe Sheble (Wizaerd)

Something I almost always do when pulling dates from a mySQL table is 
format the date column in the query itself using the mySQL function 
DATE_FORMAT()...


At 01:13 PM 4/6/01 +0100, Matt Davis wrote:
Hi I am trying to format a date extracted from my DB. I have run my query
and then have used the following to get my row data

   while ($row = mysql_fetch_array($sql_result)) {
  $title = $row["message_title"];
  $message = $row["message"];
  $event = $row["date_of_event"];

  $shortevent = date ("D j M", $event);

I am trying to take $event and make it diplay like this "FRI 06 APR" using
the date function. Although $event outputs like this "2001-04-06 00:00:00"
$shortevent outputs "Thu 1 Jan" which is unix epoch date.

Does anybody know what I am doiing wrong its probably something really
simple but I cant see what.

Matt.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Date formatting

2001-04-06 Thread Joe Stump

You need a UNIX timestamp for the second argument in date() - thus you need
to first convert your $even into a timestamp (number of seconds past 1970).

?
  $event = '2001-03-15 24:03:34';
  list($date,$time) = explode(' ',$event);
  list($year,$month,$day) = explode('-',$date);
  list($hour,$min,$sec) = explode(':',$time);

  $foo = mktime($hour,$min,$sec,$month,$day,$year)."\n";
  echo date("D j M",$foo);

?

That would work ...

--Joe

On Fri, Apr 06, 2001 at 01:13:59PM +0100, Matt Davis wrote:
 Hi I am trying to format a date extracted from my DB. I have run my query
 and then have used the following to get my row data
 
   while ($row = mysql_fetch_array($sql_result)) {
  $title = $row["message_title"];
  $message = $row["message"];
  $event = $row["date_of_event"];
 
  $shortevent = date ("D j M", $event);
 
 I am trying to take $event and make it diplay like this "FRI 06 APR" using
 the date function. Although $event outputs like this "2001-04-06 00:00:00"
 $shortevent outputs "Thu 1 Jan" which is unix epoch date.
 
 Does anybody know what I am doiing wrong its probably something really
 simple but I cant see what.
 
 Matt.
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]


/**\
 *Joe Stump - PHP/SQL/HTML Developer  *
 * http://www.care2.com - http://www.miester.org - http://gtk.php-coder.net   *
 * "Better to double your money on mediocrity than lose it all on a dream."   * 
\**/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Date Formatting

2001-02-06 Thread Richard Scott Crawford

Cold Fusion has a wonderful function called CreateODBCDate(), which takes 
as an argument any date in just about any format and returns a standard 
ODBC date format that you can plug into a database without worrying about 
conversion.

Does PHP have a similar function?  I've looked for one but can't seem to 
find it anywhere.
--
Richard Crawford (mailto:[EMAIL PROTECTED])
http://www.mossroot.com  AIM Handle: Buffalo2K
"Tomorrow, we'll seize the day and throttle it!"  -Calvin


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Date Formatting

2001-02-06 Thread Steve Edberg

At 3:04 PM -0800 2/6/01, Richard Scott Crawford wrote:
Cold Fusion has a wonderful function called CreateODBCDate(), which 
takes as an argument any date in just about any format and returns a 
standard ODBC date format that you can plug into a database without 
worrying about conversion.

Does PHP have a similar function?  I've looked for one but can't 
seem to find it anywhere.

From
http://www.php.net/manual/en/function.strtotime.php

-
"strtotime - Parse about any english textual datetime 
description into a UNIX timestamp"

If the ODBC timestamp looks like

-mm-dd hh:mm:ss

then you could do:

$Date = '1 jan 2001';
ODBCDate = date('Y-m-d H:i:s', strtotime($Date));

And if you really want, just define the function

function CreateODBCDate($DateString)
{
return date('Y-m-d H:i:s', strtotime($DateString));
}

and you can ease your CF-PHP transition :)

If you want to default to returning the current date:

function CreateODBCDate($DateString='')
{
return
(
$DateString ?
date('Y-m-d H:i:s', strtotime($DateString)) :
date('Y-m-d H:i:s')
);
}

Sorry about the weird indent style --- I was trying to avoid wordwrapping.

It doesn't specify in the docs, but I _assume_ strtotime() returns 
false if it can't figure out what the date string is...you might want 
to test that.

- steve


--
Richard Crawford (mailto:[EMAIL PROTECTED])
http://www.mossroot.com  AIM Handle: Buffalo2K
"Tomorrow, we'll seize the day and throttle it!"  -Calvin


-- 
+--- "They've got a cherry pie there, that'll kill ya" --+
| Steve Edberg   University of California, Davis |
| [EMAIL PROTECTED]   Computer Consultant |
| http://aesric.ucdavis.edu/  http://pgfsun.ucdavis.edu/ |
+-- FBI Special Agent Dale Cooper ---+

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]