473,800 Members | 2,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date formatting



I have a string saved in the format produced by date ('Ymd-Hms')

e.g.

20050215-130257

Can anyone suggest the easiest way to present this as e.g.

13.02pm, 15/Feb/2005

?

Things like strftime () don't seem to be applicable, and it's not
obviously how the general string formatting functions could be applied
here.
Martin
Jul 17 '05 #1
5 2824

Nasty format... needs to be taken apart and put back in some parsable
format, such as this:

<?php

// example date in custom format...
$t_strCustomDat e = "20050215-130257";

// disassemble...
$t_strYear = substr($t_strCu stomDate, 0, 4);
$t_strMonth = substr($t_strCu stomDate, 4, 2);
$t_strDay = substr($t_strCu stomDate, 6, 2);
$t_strHour = substr($t_strCu stomDate, 9, 2);
$t_strMinute = substr($t_strCu stomDate, 11, 2);
$t_strSecond = substr($t_strCu stomDate, 13, 2);

// reassemble...
$t_strCustomDat e = $t_strYear . "-" . $t_strMonth . "-" . $t_strDay . "
" . $t_strHour . ":" . $t_strMinute . ":" . $t_strSecond;

// now it looks like this...
//$t_strCustomDat e = "2005-02-15 13:02:57";

print date( "H.ma, d/M/Y ", strtotime($t_st rCustomDate) );

?>

---
Steve

Jul 17 '05 #2
Martin Lucas-Smith wrote:
I have a string saved in the format produced by date ('Ymd-Hms')

e.g.

20050215-130257

Can anyone suggest the easiest way to present this as e.g.

13.02pm, 15/Feb/2005

?


$ts = preg_replace(
"/-(\d{2})(\d{2})( \d{2})$/",
" $1:$2:$3",
"20050215-130257"
);

print date("H.ma, d/M/Y", strtotime($ts)) ;
JW

Jul 17 '05 #3


Thanks for the replies:
I have a string saved in the format produced by date ('Ymd-Hms') e.g.
20050215-130257 . Can anyone suggest the easiest way to present this
as e.g. 13.02pm, 15/Feb/2005 ?


On Wed, 16 Feb 2005, Steve wrote: Nasty format...
Basically the format had been chosen to append a timestamp to a flat-file
database (using the OS timestamp isn't possible because there could be
multiple instances of the same name). The format basically ensures that
the filenames will be in the correct alphabetical order, as the date is
effectively 'backwards'.
On Wed, 16 Feb 2005, Janwillem Borleffs wrote:

$ts = preg_replace(
"/-(\d{2})(\d{2})( \d{2})$/",
" $1:$2:$3",
"20050215-130257"
);

print date("H.ma, d/M/Y", strtotime($ts)) ;


Thanks - this use of preg_replace is an elegant solution which I'd
overlooked.
Martin
Jul 17 '05 #4
On Wed, 16 Feb 2005 16:33:49 +0000, Martin Lucas-Smith wrote:


I have a string saved in the format produced by date ('Ymd-Hms')

e.g.

20050215-130257

Can anyone suggest the easiest way to present this as e.g.

13.02pm, 15/Feb/2005


Just wondering if you really want the month to be shown as the minute.
The minute indicator is i, m is for the numeric month.

So ,using the date and time of your post as the example (at the top)
date('Ymd-Hms') gives 20050216-160249
date('Ymd-His') gives 20050216-163349

You may really want the month but if not this will save you some bug
hunting :-)

--
Regards - Rodney Pont
The from address exists but is mostly dumped,
please send any emails to the address below
e-mail ngpsm4 (at) infohitsystems (dot) ltd (dot) uk
Jul 17 '05 #5


On Thu, 17 Feb 2005, Rodney Pont wrote:
On Wed, 16 Feb 2005 16:33:49 +0000, Martin Lucas-Smith wrote:


I have a string saved in the format produced by date ('Ymd-Hms')

e.g.

20050215-130257

Can anyone suggest the easiest way to present this as e.g.

13.02pm, 15/Feb/2005


Just wondering if you really want the month to be shown as the minute.
The minute indicator is i, m is for the numeric month.

So ,using the date and time of your post as the example (at the top)
date('Ymd-Hms') gives 20050216-160249
date('Ymd-His') gives 20050216-163349

You may really want the month but if not this will save you some bug
hunting :-)


Thanks - yep, realised this yesterday, when the files started being
written out of sequence...
Martin
Jul 17 '05 #6

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

Similar topics

3
2188
by: Ed | last post by:
Hi there, My problem is the following: When I assign a custom formatted Date & Time to a Date variable it loses it’s formatting. Ex. 2005-06-07 15:46 now when I assign this to a variable of type Date or DateTime this becomes 2005/06/07 03:46:00 The same code work flawlessly on various other machines, thus I presume this is settings related. I know that the Time function in VB.NET reads from the system time, which you set in...
4
2070
by: Paul | last post by:
Hi, Everything went fine getting a short date format out of SQL into my DataGrid with this: <%# DataBinder.Eval(Container.DataItem, "Created", "{0:d}")%> Then I got too fancy in SQL and started doing a RTRIM(date) when I was retrieving the data. That screwed the pooch big time. Suddenly I lost
4
1627
by: dhnriverside | last post by:
Hi peeps I have a datepicker control that's providing dates in the format dd/mm/yyyy (UK). I want to convert this to "yyyy-mm-dd" to store as a text field in my database (had lots of problems with date conversions using "proper" data fields). I used to use ASP, and it was easy, using a combination of Left() Mid() and
12
1763
by: Rob T | last post by:
I'm storing a date/time into a SQL table of type datetime. I need it to be precise so the value is stored to the 1000th of a second. ie "insert into myTable mydate values ('08/05/2005 2:56:11.987'). This works fine...if you check the value in the table with query analyzer, it shows in there properly. Now, in my app, I'm executing the same query (that I used in QA) and storing tha in a dataview. If I break and watch the program, the...
2
2168
by: johndcal | last post by:
Hello All, I have a date value that I pull from a .csv file. After reading the file and storing the values in an array the value of the date could be found in $array, for example. ============================================================= while (($data = fgetcsv($handle,5000, ",")) !== FALSE) { $mydate = $data; // here is the array value that holds the date }
2
2272
by: David Veeneman | last post by:
How does one format a date column in a GridView control? I had assumed that the DataFormat string would do it, but MSDN only shows numeric formatting codes. Can dates be formatted using that property, or is it done some other way? Thanks in advance. -- David Veeneman Foresight Systems
3
3318
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when the field should only be showing one or the other (date or time). Even on the back end of the database where the column properties are, I have chosen the smallest date/time formats. When the aspx page runs, it shows the date and time (ie:in a...
21
3390
by: Darin | last post by:
I have an applicatoin that works 100% perfect when running on a machine setup for English (United States), but when I change it to Spanish (Mexico), the dates start giving me fits. THe reason is USA is mm/dd/yyyy and mexico is dd/mm/yyyy. So, with the computer set to mexico, any standard CDATE function is going to return the date in the dd/mm/yyyy setting since that is what the computer is set to. I want to be able to enter a date in...
7
2108
by: creative1 | last post by:
Hello everyone. I am experiencing a strange problem that I can't fix on my own. I think I need expert's suggestions for this. The problem is: I want to print account statement (or any other report) from VB form based on an entered date in the masked fields (dd/mm/yy). I am using one form to display five reports. I send date to display report after formatting it (m/dd/yy). When I enter date range like this in masked textbox (DD/MM/YY) ...
9
2943
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
0
9690
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
9550
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
10273
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10250
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
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...
0
6811
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
5603
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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.