473,769 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2487
date() requires a unix timestamp, which is differant from the mysql
timestamp. therefore, you must create one:
$yy = substr($lastdat e, 0, 4);
$mm = substr($lastdat e, 4, 2);
$dd = substr($lastdat e, 6, 2);
$hh = substr($lastdat e, 8, 2);
$mm = substr($lastdat e, 10, 2);
$ss = substr($lastdat e, 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(sta mp, '%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.supernew s.com>,
go***********@b urditt.org (Gordon Burditt) wrote:

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

Gordon L. Burditt

Thanks.

$last_donation= mysql_query("SE LECT DATE_FORMAT($ye ar_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(sta mp, '%m/%d/%y'), ...
if you absolutely insist on writing non-Y2K-compliant code.

Gordon L. Burditt

Thanks.

$last_donation =mysql_query("S ELECT DATE_FORMAT($ye ar_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
6189
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 functions.... Any help would be appriciated..
11
4079
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 wrong way. Here what I have but wow I get a wrong date. $cdate = date("r",$cdate); Please help!! I appreciate any help you can give. Rick
15
43016
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 mediate between webapps and arbitrary database backends using JDBC. I am very unwilling indeed to write special-case code for particular databases. Our code has worked satisfactorily with many databases, including many instances MS SQLServer 2000...
0
5038
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 deal with this and will only accept dd/mm/yyyy. Undaunted, I find that one can set the format when exporting a timestamp. So I thought of casting the date to a timestamp and then exporting with timestamp format set to dd/mm/yyyy. But one isn't...
2
8524
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 selection criteria to be in the format 2005-01-01-13.24.54.000000 or it will not find it. Is there a configuration parameter that can be set in the DB2 instance or if there is a pre-SQL command (like Oracles Alter Session Set NLS_DATE_FORMAT=....)?...
9
2045
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 dtmCtl As Date Dim dtmTest As Date Me!cbxEndTime.Requery Me!cbxStartTime.Requery
3
1122
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 write: <xsl:value-of select="A/B" />, I get first node from unordered list
9
2941
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 how I can/should do that? Or possibly point me to an on-line explanation? Thanks ps: if it makes any difference, the data is coming from a MS Access
3
52572
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
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7403
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.