Format Carbon::Now issues on Seeder - php

I'm inserting some test data into my db for a posts table.
I am trying to format the Carbon post created date to read as for example if the post was created on 20-06-2016 it would read 20th June, 2016.
Here is my code
'post_created_date' => Carbon::now()->format('d-m-y')
How do I format it to display this? Currently everything I try doesn't work and it just defaults to Y-m-d
Thanks so much for any help.
Please don't get the wrong idea if you think Im being lazy, I've read the data mutator docs on the laravel website but I'm struggling to see a solution.

For a data format such as 20th June, 2016.
'post_created_date' => Carbon::now()->format('mS F, Y')
Source the php date format.
Though, I don't recommend you save dates in your database in this format. It's better to save the date in regular mysql format and do the formatting in the view.

Related

Human to PHP time interpreter

We've got a collection of messy data, and trying to unify it.
Lots of services let you type dates out into different formats and they correctly understand them, but cant think what the process is called, or how we could go about doing this in PHP, if there is a library that already provides this.
So we've got time and dates in an old database we've inherited, and trying to clean it up a bit, some of the formats look like
9pm
9:00pm
25th march 2015
its a complete mix and match, does anybody know of any libraries or ways to be able to parse these into a universal format?
the problem here is the information you have is inconsistent! you need to normalize it some way, IT might actually be worth getting into an excel sheet and try to match the date time fields into some kind of regex and filter like that, is probably what i would do, so you can separate the different formats and tackle each format individually.
A program will have to first identify the format you're feeding it and then it will spit out whatever format you want!
you can use this strtotime() PHP with this to turn it into any format
http://php.net/manual/en/function.date.php

Convert date to string in php to zulu UTC format, not a duplicate topic?

Hi I have posted this question before, but people marked it as a duplicate questions. so I didn't get any answer.
I am trying to get the current date/time in the format for example "20150701183741.941Z', I am not sure what the technical term for this format is called. some people told me that it is UTC/ZULU time format.
I have tried generate the above format by using below codes.
date_default_timezone_set("UTC");
echo "formatted currenttime: ".date("YmdHis.ue", time());
but it returns it in the format "20150701144710.000000UTC", this is close to what I need, but I am not able to get at the end something similar to ".941Z".
Please note that this isn't a duplicate question. I posted it earlier but got marked as a duplicate and that one is now inactive. Thanks very much for your help.
The official documentation of date() says that date() always generates 000000 because it takes an integer parameter, and that DateTime() does support microseconds:
http://php.net/manual/en/function.date.php
However, this comment seems to say that DateTime() doesn't support microseconds either:
http://php.net/manual/en/class.datetime.php#108970
So I guess you're out of luck with that :(
Why don't you use the Carbon Library? It's one of the superb ways to handle data and time. Just take a look into the official documentation at http://carbon.nesbot.com/docs/

Wordpress most flexible format for dates

I am using a library called Custom Metaboxes and Fields for Wordpress to add meta data to my custom post types. It's an event website.
I had it all going, but started to have issues with sorting when trying to filter the adjacent_post_links from singe posts.
I figured it might be that I am storing the date in m/d/y and not Y/m/d.
So, i've started over trying to work with a UNIX date timestamp as I have read this is the way to go. Now, I am having issues with my custom wp_queries pulling my filtered posts on the front page. I think it has to do with needing to work with timezones.
Anyways, over the long run, what are the best practices in storing date in mysql? I've also been reading about using STR_TO_Date() to properly format date so that you can order and compare dates if needed. Would this be an option if I went back to dates being stored in m/d/y .
Thanks
If you store dates as Unix timestamps in the database, it 'll gives you lots of trouble because it is not easily readable.for Example(unix format): '1410738238'
if you store as datetime format in the database, it is easy readable efficient and very flexiable,also mysql provides a lot of date functions.for Example(datetime format): '1970-01-01 00:00:01'
for more information http://dev.mysql.com/doc/refman/5.1/en/datetime.html

Changing the date format from 2011-12-08 to December 8th, 2011 [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Convert one date format into another in PHP
I am currently pulling from my SQL database the event dates i.e in the table field date it will display (2011-12-08) however i wish to have it output December 8th, 2011 rather than 2011-12-08 when display through php on my website. Any ideas on how to go about this?
As people have said, for questions like this please search around first before asking since many places on the web and many other questions in stackoverflow already cover this. That said, my advice is to store the date in the database as a datetype because it will allow mysql to do its operations easier then convert the the human readable form upon displaying it using the php date function which would use format "F jS, Y" for what you want. Good luck and welcome to stackoverflow.

Reading date from Excel using PHP giving one day more

I am trying to read dd/mm/yyyy date from Excel. It is behaving very inconsistently. At times it adds one day more to the actual date in the cell and at times give the correct date.
The code:
$pdiDate_key = array_search('PDI Date',$excel->sheets[0]['cells'][1]);
Based on your code example, I'm going to guess that you're using PHP-ExcelReader to retrieve the dates from Excel. If I'm right, then, well, there is a known error in Excel that PHP-ExcelReader doesn't handle. The "bug" report is here:
SourceForge.net: PHP-ExcelReader: Detail: 2388545 - Wrong Date
The comments at the bottom of that page include code for a function to fix the error.

Categories