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 have a form which user submits and I get the current time and date in the database and facebook ID of the user as well, As per rule the user can fill the form only once in a week, so if he fills the form on Tuesday, he is not eligible to fill the form unless the week is complete, (Only eligible to complete the form again on next Monday)
I am trying to find some php function for weeks but couldn't get so, Anyone can help me what can be done for this logic?
I have date/time in the db for me.
First, you are basically looking for
$date = "2014-10-13";
$week=date("W", strtotime($date));
or even use it this way
$date = "2014-10-13";
$date = new DateTime($date);
$week = $date->format("W");
( http://php.net/manual/en/function.date.php )
Related
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 1 year ago.
Improve this question
I am looking for a similar PHP date function. I need the current month's first day. This month is September. the September month's first day is Wednesday. I need this one like this. Advance Thanks
Here you go:
$thisMonthsFirstDay = (new DateTime('first day of this month'))->format('l');
Also always take a look into the documentation, you can learn a lot from there.
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
I am trying to create a so-called inline calendar for a schedule, where all the current month's dates will be displayed in a 1st table row, like this:
It should display all the dates of the current months and days of week. Also, in the every date cell there will be a select input to choose a work shift, so is it possible to assign some data-attributes to corresponding cell's input (like data-date)?
Is it possible of doing that in the Laravel Blade? By the way, I am planning to display the previous month's dates in another table as well (like for reference).
That's definitely possibly. Since it sounds pretty interactive to me, I would probably combine it with a JS framework like Vue.js. The benefit of using Vue in this case, is that you won't visibly have to submit a form (meaning that the page will refresh) when selecting a work shift: you can easily do this under the hood by sending an Ajax call. It is however not necessary to accomplish what you want.
Using Carbon, you can get the days in the current month by doing:
$period = Carbon\CarbonPeriod::create(Carbon\Carbon::now()->startOfMonth(), Carbon\Carbon::now()->endOfMonth());
foreach($period as $date)
{
$dates[] = $date->format('d-m-Y');
}
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 3 years ago.
Improve this question
I got this .csv file where I have employee number, name and birthday. Birthday comes in dd-mm format (I live in Mexico), how can I convert it to proper date, so I can call date function date('y-m-d', $date) in order to store it in the database?
You can't! At least not reliably. A date must contain the year.
Consider this example:
$dt = DateTime::createFromFormat('d-m', '29-02');
echo $dt->format('Y-m-d'); // 2019-03-01
If an employee's birthday is on the 29th of February and you store it in DB as Date then you are loosing information. To keep the original information intact you need to store it in the format you have received it in, as a VARCHAR field of suitable length.
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 7 years ago.
Improve this question
I want to know how to display time since a user has submitted the form on my website. So for example when the user submits the form I was to display
"Thank-you for your submission. You have been logged in for 0 seconds" depending upon the time that has elapsed." Can I use the time() function but am not sure to process it.
When the user login store the time in a session variable like this:
$_SESSION['usertime'] = time();
Then when the user submits the form you simply minus the current time from that session variable time.
echo "You have been logged in for "
. round(abs($_SESSION['usertime']- time()) / 60,2). " minute";
You can use time function like this.
<?php
$time=time();
echo($time . "<br>");
echo(date("Y-m-d",$time));
?>
echo date("Y-m-d H:i:s");//current date
echo date("H:i:s");//current time
you can search in net before ask:D
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 need to get my country's current date. Currently my project is getting the user's date.
Here are my questions:
how to get my country's current date?
If I'm running my php site in my localhost (wampp), will I still get my country's current date? (I have an internet connection by the way).
PHP fetches time info from the server (your local system in this case). Then, with date_default_timezone_set() you can set any time zone you need.
Please, try this simple code and see what happens:
America/Montreal:<br>
<?php
date_default_timezone_set("America/Montreal");
echo date("Y/m/d H:i:s", time());
?>
<br>
Asia/Aden: <br>
<?php
date_default_timezone_set("Asia/Aden");
echo date("Y/m/d H:i:s", time());