473,411 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

More noob nonsense - output format for a timestamp date variable

hph
Okay, another trivial matter that I can't solve.

I have a variable - $lastdate - that is the latest date any record in a
MySQL database was updated. Its MySQL format is TIMESTAMP.

If I say [echo $lastdate] I get the output I'd expect - 20060424221549
which is a YYYYMMDDHHMMSS format.

I'd like to be able to display that using a format of mm/dd/yy with no
leading spaces on the month and day. I don't know what the php command
is to do this. In other words, I'm trying to display a variable -
$lastdate - formatted a certain way. I know that the formatting string
n/j/y will get my output looking as I'd like, but I can't figure out how
to apply that to my variable.

Thanks to those who've helped me with my questions the last two days.
This seems to be the last piece of information I can't find right now.
Apr 26 '06 #1
4 2460
date() requires a unix timestamp, which is differant from the mysql
timestamp. therefore, you must create one:
$yy = substr($lastdate, 0, 4);
$mm = substr($lastdate, 4, 2);
$dd = substr($lastdate, 6, 2);
$hh = substr($lastdate, 8, 2);
$mm = substr($lastdate, 10, 2);
$ss = substr($lastdate, 12, 2);
$date = mktime($hh, $mm, $ss, $mm, $dd, $yy);
$whatYouWant = date('n/j/y', $date);

hph wrote:
Okay, another trivial matter that I can't solve.

I have a variable - $lastdate - that is the latest date any record in a
MySQL database was updated. Its MySQL format is TIMESTAMP.

If I say [echo $lastdate] I get the output I'd expect - 20060424221549
which is a YYYYMMDDHHMMSS format.

I'd like to be able to display that using a format of mm/dd/yy with no
leading spaces on the month and day. I don't know what the php command
is to do this. In other words, I'm trying to display a variable -
$lastdate - formatted a certain way. I know that the formatting string
n/j/y will get my output looking as I'd like, but I can't figure out how
to apply that to my variable.

Thanks to those who've helped me with my questions the last two days.
This seems to be the last piece of information I can't find right now.


Apr 26 '06 #2
>I have a variable - $lastdate - that is the latest date any record in a
MySQL database was updated. Its MySQL format is TIMESTAMP.
I recommend using date_format() in MySQL.
If I say [echo $lastdate] I get the output I'd expect - 20060424221549
which is a YYYYMMDDHHMMSS format.

I'd like to be able to display that using a format of mm/dd/yy with no
In case you haven't heard, years have 4 digits. Ever hear about
the Y2K problem?
leading spaces on the month and day. I don't know what the php command
is to do this. In other words, I'm trying to display a variable -
$lastdate - formatted a certain way. I know that the formatting string
n/j/y will get my output looking as I'd like, but I can't figure out how
to apply that to my variable.


SELECT DATE_FORMAT(stamp, '%m/%d/%y'), ...
if you absolutely insist on writing non-Y2K-compliant code.

Gordon L. Burditt
Apr 26 '06 #3
hph
In article <12*************@corp.supernews.com>,
go***********@burditt.org (Gordon Burditt) wrote:

SELECT DATE_FORMAT(stamp, '%m/%d/%y'), ...
if you absolutely insist on writing non-Y2K-compliant code.

Gordon L. Burditt

Thanks.

$last_donation=mysql_query("SELECT DATE_FORMAT($year_data[2],
'%j/%n/%Y'");

gave me what I wanted. $last_donation was a variable that I later
echoed, and year_data was a result array into which I'd fetched data,
including a TIMESTAMP data field.

I'm all for Y2K compliance (I won't, however, be around when Y10K
becomes an issue...), but in this case, I'm simply displaying a date in
a format that, I think, seems to appeal to the majority of people in the
US who think of dates as just dates and not data.

Thanks for your patience in answering my trivial questions.
Apr 27 '06 #4
>>
SELECT DATE_FORMAT(stamp, '%m/%d/%y'), ...
if you absolutely insist on writing non-Y2K-compliant code.

Gordon L. Burditt

Thanks.

$last_donation=mysql_query("SELECT DATE_FORMAT($year_data[2],
'%j/%n/%Y'");

gave me what I wanted. $last_donation was a variable that I later
echoed, and year_data was a result array into which I'd fetched data,
including a TIMESTAMP data field.


This won't work. Best case, $last_donation is a MySQL result handle,
not a string. You need to fetch a row and get the right element
and echo *that*.

Ideally, you don't use a separate query, you get the timestamp in
the format you want it (using DATE_FORMAT) instead of the format MySQL
uses (just selecting the timestamp field).
I'm all for Y2K compliance (I won't, however, be around when Y10K
becomes an issue...), but in this case, I'm simply displaying a date in
a format that, I think, seems to appeal to the majority of people in the
US who think of dates as just dates and not data.

Thanks for your patience in answering my trivial questions.

Apr 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: point | last post by:
Hi... I have this format 2003-12-01 18:46:20.0 And would like it to be 01-12-2003 18:46:20 I know it can be done vis string cuts and explodes but ther's got to be a better way using time...
11
by: Rick | last post by:
I am going crazy on how to format a simple date. I have this in my MySQL table. "2005-03-10 08:44:21" and I want it to format out like "3/10/2005" or "03/10/05" but I seem to be going at it the...
15
by: Simon Brooke | last post by:
I'm investigating a bug a customer has reported in our database abstraction layer, and it's making me very unhappy. Brief summary: I have a database abstraction layer which is intended to...
0
by: James Foreman | last post by:
Looking at the documentation on EXPORT, when exporting a date column it will automatically use yyyymmdd. One could choose to use ISO format, but unfortunately the client I'm exporting to can't...
2
by: dbztax | last post by:
Hi all, In Oracle and SQL server I have a date/time of 01/01/2005 13.24.54. If I do a select using the date field with a criteria of 01/01/2005 it will find it just fine. DB2 requires the...
9
by: deko | last post by:
What is it with these dates? What are they so much trouble? All I want to do is subtract an hour, but not if that makes dtmTest less than dtmClt. Dim dtmStart As Date Dim dtmEnd As Date Dim...
3
by: Pravljica | last post by:
Hello, Now I have this: <xsl:for-each select="A"> <xsl:sort select="B" /> </xsl:for-each> Now I would like to get first node from this sorted list (which has the smallest value). But if I...
9
by: Martin | last post by:
I'm retrieving some records from a database. One of the fields contains a date/time. I would like to format it as I send it out to the table in the displayed page. Can some one please tell me...
3
by: yogi | last post by:
Hi, I am working on a database that has a variable with timestamp values. I wanted to convert the variable from timestamp to yyyy-mm-dd format. Thanks in advance Yogi
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.