DateTime::createFromFormat month name [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm using DateTime::createFromFormat in PHP like this:
$month = DateTime::createFromFormat("Y-m-d", '2014-08-01');
But echo $month is showing up as 08. How can I display it as a 3 letter name, i.e.: Aug?

Use capital M instead of m .
$getMonth = DateTime::createFromFormat("Y-m-d", '2014-08-01');
If you already have the date variable created then you can use directly the below code
$month = $getMonth->format('M');

Related

How to get users greater than 25 years but i have only DOB column in mongoDB. how can i get in laravel [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
dob is date of birth and dob column in only dob's year
This is my code
$voters = DB::collection('users')->whereDate(Carbon::parse('dob')->age, '<', 25)->get();
This is my table
id, name, dob
1, Peter, 1974
2, John, 1988
3, Semi, 1995
Can you try this:
$now = Carbon::now();
$filterYear = $now->year - 25;
$voters = DB::collection('users')->where('dob', '<', $filterYear)->get();
Please dont forget to use Carbon on top of the class.
You can check the years difference:
$voters = DB::collection('users')->whereDate(Carbon::now()->year - 25, '>', 'dob')->get();

Check when a information provided from sql changes in php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want to get a warning when a date is different like:
I have a while and wanted to when it reaches to a different date, it warns me
$hist=mysqli_query($db, "SELECT * from history");
while($his=mysqli_fetch_assoc($hist)){
If(certain_date != last_date){
echo certain_date;
}
}
Certain date and last date is the ones I wanna get
This is simply done like this
$hist=mysqli_query($db, "SELECT * from history");
$last_date = '';
while($his=mysqli_fetch_assoc($hist)){
If($his['ano'] != $last_date){
echo $his['ano'];
$last_date = $his['ano'];
}
}

Write a program to convert the age of human in years and display the age in month,week and days [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
im new with the php and still studying about php and more. i have a question.
How to convert the age of human in years and then display the age in months,week and days.
(hint:1years=365days). i hope anyone could help me.thanks
You should look at the DateTime class
$previousDate = '1986-09-04 14:05:43';
$startDate = new DateTime($previousDate);
$endDate = new DateTime('now');
$interval = $endDate->diff($startDate);
echo $interval->format('%y years, %m months, %d days');

change specific values of array in PHP [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
<?php
$x=6;
$y=9;
$time = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
for ($i=$x;$i<=count($y);$i++)
{
If($x!=$y)
{
$time[$i]=1;
}
}
?>
Depending on the value of x and y,the values in array should change.
In this example... array[5] until array[8] should be value 1.
The value of x and y will not same.
Not a very good question, but I'm a little bored. So for fun:
array_splice($time, $x-1, $y-$x-1, array_fill(0, $y-$x+1, 1));
Not exactly sure of the logic using 6 and 9 and array[5] until array[8] is, but adjust the numbers to fit the range.

Automatically edit row based on date [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am currently trying to create a script/function that should set a value to all items (eshop goods) old 15 days or older.
This script will be used as cron.
Date is stored in database as integer, but I don't exactly know how to approach the 15 days gap.
Could somebody help me out please?
Thank you.
You can try something like this
$integer_format = strtotime("-15 days");
$dateTime_format = date("Y-m-d h:i:s A T",$integer_format);
echo 'In integer format: '.$integer_format.'</br>'; //1403953190
echo 'In date time format: '.$dateTime_format.'</br>'; //2014-06-28 12:59:50 PM CEST

Categories