Solved

Converting the dateTime datatype to AP style date

Posted on 2008-06-24
9
947 Views
Last Modified: 2013-12-12
How to I convert DateTime - 2008-04-24 00:00:00.000 to AP stype date?
AP stype would be:
Jan,
Feb
March
April
May
June
July
Aug
Sept
Oct
Nov
Dec

Is there any function out there?
Any ideas/thoughts?
Thanks
0
Comment
Question by:martyje
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
9 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21859469
DATENAME(month, yourfield)
0
 
LVL 1

Expert Comment

by:morristhebear
ID: 21859634
Using PHP, you could use the function below.

(This will return Jan, Feb, March, ..., Dec; change the M (the first argument for the date function) to match your needs, using these options (http://www.php.net/date)
<?php
	
	function nice_date ($string_date) {
		return date ('M', strtotime ($string_date));
	}
	
?>

Open in new window

0
 

Author Comment

by:martyje
ID: 21860123
Sorry, didn't explained it well, that 'll return only the month. I am trying to convert it to the following format
June 23, 2008 etc...
March 04, 2007
Jan 12, 2008

Thanks.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21860176
this expression will do:

CONVERT(varchar(11), yourfield, 109)

Open in new window

0
 
LVL 1

Expert Comment

by:morristhebear
ID: 21860234
My function can be changed easily to display the date in different formats, for the format you requested, use this instead:
<?php
	
	function nice_date ($string_date) {
		return date ('M d, Y', strtotime ($string_date));
	}
	
?>

Open in new window

0
 

Author Comment

by:martyje
ID: 21860273
morristhebear: the function works great but, I am trying to get the date format as in the list above.
It should say March not Mar
Any month that has four letters, it should say the whole month or first there letters such as Jan for January.

Thanks.
0
 
LVL 1

Expert Comment

by:morristhebear
ID: 21860352
There's no format for that type of date in the PHP manual.  Maybe this will work though, any month with more than 5 letters (i.e January, February, August, September, October, November, December), show the abbreviation, else show the whole month name (i.e - March, April, May, June, July).
<?php
	
	function nice_date ($string_date) {
		if (strlen(date('F', strtotime ($string_date))) > 5) {
			return date ('M d, Y', strtotime ($string_date));
		} else {
			return date ('F d, Y', strtotime ($string_date));
		}
	}
	
?>

Open in new window

0
 
LVL 1

Expert Comment

by:morristhebear
ID: 21860503
Actually, I didn't read what you wanted properly.  I've looked at your list of months you provided and come up with this, this should do the months exactly how you want them, haven't tested though...
<?php
	
	function nice_date ($string_date) {
		$ap_dates = array (
			'Jan', 'Feb', 'March', 'April',
			'May', 'June', 'July', 'Aug',
			'Sept', 'Oct', 'Nov', 'Dec'
		);
		return $ap_dates[date('n')-1] . ' ' . date('d') . ', ' . date('Y');
	}
	
?>

Open in new window

0
 
LVL 1

Accepted Solution

by:
morristhebear earned 250 total points
ID: 21860526
Forget the above, that will return todays date in the format you requested.  This should be it:
	function nice_date ($string_date) {
		$ap_dates = array (
			'Jan', 'Feb', 'March', 'April',
			'May', 'June', 'July', 'Aug',
			'Sept', 'Oct', 'Nov', 'Dec'
		);
		return $ap_dates[date('n', strtotime($string_date))-1] . ' ' . 
			   date('d', strtotime($string_date)) . ', ' . 
			   date('Y', strtotime($string_date));
	}

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Magento: different theme for Pc and for mobile devices 4 71
check mysql insert 12 39
Date comparison to same 'wednesday' of previous year 3 28
Change a button after e-mail 4 19
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question