Difficulty converting date in format yyyy-mm-dd to textual date format like Monday 21 Jan 2012 PHP - strtotime

I am trying to convert a date in format (yyyy-mm-dd) to a textual date format like Monday 21 Jan 2012 using PHP. I have tried using mktime() function but I'm a novice and I cant figure it out.
Any help will be grealty appreciated.
e.g :- convert 2012-04-27 => Friday 27 April 2012
Thanks.

You can make use of the DateTime class (which is recommended over strtotime):
$date = new DateTime($date_string);
$textual = $date->format("l j M Y");

echo date("l j M Y", strtotime('2012-04-26'));

Related

Query function behaving strange with dates in google sheets

Function which isn't working: =QUERY(A:B, "SELECT A WHERE B > " & D1, 0)
What it's looking at:
A
B
Strings
13 Feb 2023
Strings
18 Feb 2023
Strings
21 Feb 2023
Cell D1 =
10 Feb 2023
Trouble shooting:
The query is coming up no results. All dates are numbers, when I format them as numbers instead of dates it works, when I format them as DD MMM, it works, but when I format them as DD MMM YYYY it doesn't work and this is the format I need it in.
Question
Why is Query so sensitive to date formats?? I always use different date formats depending on the sheet and vlookup has no issue with this. Also why on earth would it just not accept one format? I really want to learn for future
for query you may use:
=QUERY(A:B, "SELECT A WHERE B > date'"&text(D1,"yyyy-mm-dd")&"'")
if you wish to avoid the query confusion; you may just go with simple filter Fx
=filter(A:A,B:B>D1)

Validate Date String

We have a new field being added to our app where the client wants to be able to put in Sept 22. The input will be part of an import with 100 or so records. I know there are many libraries for parsing it but we want to be able to validate it. In case someone were to make a typo. Any thoughts or libraries to do this?
DateTime.parse will parse "Sept 22" with current year.
you can just make a dateTime with specified year as
date = DateTime.parse("Sept 22")
date_time_with_year = DateTime.new(year, date.month, date.day)
Check out Chronic
You can do things like
Chronic.parse('may 27th', :now => Time.local(2000, 1, 1))
#=> Sat May 27 12:00:00 PDT 2000
It will attempt to guess what the string was trying to convey, by default (ie: "Sept 27" will actually parse to something like 2013-09-27 12:00:00 -0500

date format dilemma?

I have this date from twitter, this represents the exact date the tweet is published,
Sun, 01 Jul 2012 19:05:54 +0000
what I want is to make its format into MM/DD HH:MM, tried to look for php date formats but couldn't find a way to make it look exactly the way I want it to be. Can someone please help? Thanks.
print date('m/d h:i',strtotime('Sun, 01 Jul 2012 19:05:54 +0000'));
The date function for php is a good place to find all sorts of information on this.
This would be pretty simple to search and figure it out. You are looking for a date... ahh, date, that is a php function. When you look that up you will see that it takes some params, a format and a time stamp. Well... You do not have a time stamp you have a string. how do i convert a string to time? Wait, there is a strtotime function in php. There you have it... run the date function in php with the way you want the date to look and then convert the string to timestamp with strtotime
<?php
date_default_timezone_set("UTC");
$string = "Sun, 01 Jul 2012 19:05:54 +0000";
$timestamp = strtotime($string);
print "Date is " . date("m/d H:i", $timestamp) . "\n";
?>
You may have to change timezone, and/or add/subtract seconds or use local time functions to convert between TZ's.

how to change: Sun Jan 01 00:00:00 BRST 2006 to 2006-01-01 00:00:00.0

Hey guys, how can I tranform the format of datePicker that came to my action params?
My actual Date attribute doesn`t accept this"Sun Jan 01 00:00:00 BRST 2006" type, only "2006-01-01 00:00:00.0 " for example.
How can I deal with it?
It's hard to investigate in questions that don't provide required information to reproduce the issue. In your case, that would be the error type, and message, and the related code snippets, at least. -
Normally, your datePicker result "Sun Jan 01 00:00:00 BRST 2006" should be perfectly fine with standard code like that:
Controller action method:
def index = {
Date date = params.datePicker
[date: params.datePicker ?: new Date()]
}
GSP:
<g:datePicker name="datePicker" value="${date}" />
Now let's go on to wild guesses:
In case you're trying to parse that date string using the SimpleDateFormat class, the corresponding conversion pattern would be:
Date date = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy")
.parse("Sun Jan 01 00:00:00 BRST 2006")
resp.,
Date date = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy")
.parse(params.datePicker)
It's also possible to register a CustomDateEditor, but there shouldn't be a need to do with a datePicker.
After all, the datePicker result should be converted to a Date, automatically, as depicted in the first sample. - If it still does not, please clarify your issue.
Why you don't use Joda-time instead of Date that has many deprecate methods, and is less powerful.
In the gsp file then you just need to use: .toString("format")

Date/Time conversion problems from Rails to Flex?

I am getting the following error:
TypeError: Error #1034: Type Coercion failed: cannot convert "2010-01-02 23:28:17 UTC" to Date.
I am using WebORB to transfer data between Rails and Flex. The data coming from Rails is of type: 'ActiveSupport::TimeWithZone'. I am trying to assign it to a Flex 'Date' data type.
What am I missing?
From the documentation: http://www.adobe.com/livedocs/flex/3/langref/Date.html#Date()
If you pass a string to the Date class constructor, the date can be in a variety of formats, but must at least include the month, date, and year. For example, Feb 1 2005 is valid, but Feb 2005 is not. The following list indicates some of the valid formats:
Day Month Date Hours:Minutes:Seconds GMT Year (for instance, "Tue Feb 1 00:00:00 GMT-0800 2005", which matches toString())
I think in Rails, what you need to do is calling strftime to format the date output that's going to be sent to Flex
time_with_zone.strftime("%a %b %d %H:%M:%S %z %Y") # => "Sun Jan 03 20:58:16 +0700 2010"
Thanks for the help but, oddly, that wasn't it. Your help, Sikachu, did put me on the right track. I couldn't simply assign the returned result--I had to feed it into the constructor. So, instead of doing this, which didn't work:
var flexDate:Date = server_result.date;
I did this, which works:
var flexDate:Date = new Date(server_result.date);

Resources