I would like to make a calender schedule for my work. That means that everyday I work I will put it in a form, where it is connected to my MySQL databases. From a page I would like to see how many hours I had in a period. I was thinking that there was 2 of these icons:
http://www.calendar123.org/calendar123/november-2012-calendar-printable-16.jpg
where I could those a period, and get it displayed. I have the connection to my database etc, but how do I incorporate a calendar function like the picture on my webpage, where I can choose dates from my database? I am not familar with PHP, but I am working with html, xml, java, javascript, css and MySQL
Hope somebody can help me.
Best Regards
Mads
You'll probably want to use the jQuery datepicker but there are tons of them out there.
UPDATE:
It acts like a textbox on the PHP side. You'll get a string date in your $_REQUEST array. You'll want to use the strtotime() function to convert that into a PHP timestamp. Then use the date function to convert that back into a MySQL formatted date like so:
$date = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $_REQUEST['date_html_id'])));
Now $date can be inserted directly into a MySQL DATE or DATETIME field.
Related
Can someone please assist me with the following problem. I am using Carbon to get the current time. Once I got the time and send it to my (myphpadmin) database it displays the whole date and time and not just the time. Here are all the code being used.
Laravel Code:
$date = Carbon::parse(now())->timezone('GMT+2');
$time = $date->toTimeString();
$UserRequest->finished_at = $time;
SQL Database layout and format:
Display: (Incorrect)
I have literally tried all the custom formatting from Carbon docs nothing sends over just the time.
I need this format -> 12:09 pm
Table Structure:
The problem more complicated than you describe.
First looks as finished_at is datetime field, so you can not store only date in this field. Sure, you can change the column format to time and store only time part. But this approach can cause problem with overdate date (started_at may be previous day or early).
So I think you need not change your storing flow, but you can change representation flow by using appropriate format
Can anyone tell me how to display something like this in wordpress? I know the SQL code for it, just not how to display it in Wordpress. Ive tried to google plug ins etc with no luck.
You can try NUMBER_FORMAT or MONEY_FORMAT functions of PHP and format your data before displaying it on page. You do not need to rely on sql.
Number Format
Money Format
If you insist using sql and try showing data as it comes from database you can query your data as shown below.
FORMAT()
CONCAT('$', FORMAT(VAL, 2))
I'm not quite familiar with wordpress html editor but I think you can do something like this:
Make an <input> field with text type, remove the borders and set as read-only. Then send the value from sql query - make sure the value looked exactly as you want it - according to your example there, the value should be '$6,621,280'. Use that value to show in the <input> field.
Refer to this jsfiddle example : https://jsfiddle.net/6vqhc1sL/3/
I would like to ask how to add datetime ('Y-m-d h:i:s') format field for the SQL.
The name of my table is groups, the name of the field is date_add
i am using cake PHP 3, i want to use the timezone Australia/Perth but i don't know how to begin.
I successfully displayed added my date using
$group->date_add = date("Y-m-d h:i:s");
However, the result for the time is not correct with the timezone.
Datetime in PHP in general
Per the documentation of DateTime you can use all options available for the date() functions for formatting. Your main mistake in the formatting is the difference betweetn a y and a Y being the difference between a year in two and a year in four numbers.
Secondly you say you want to add the correct time zone. This is a bit odd however since you always want to add the same time zone. If you want to convey the fact that all your dates are Australia/Perth as information why do you not simply add that text after it?
If you mean this is a problem since you store the information in a different time zone to begin with and thus have a conversion problem you can set the correct time zone on the DateTime object itself. But you need to be sure the DateTime object is constructed with the correct original time zone to begin with. Observe the following code for an explanation:
<?php
$DateTime = new DateTime(); // This is now Europe/Amsterdam for my laptop
var_dump($DateTime->format('dmY h:i e'));
// result of var_dump is: string(31) "13102015 12:00 Europe/Amsterdam"
$DateTime->setTimeZone(new DateTimeZone('Europe/London'));
var_dump($DateTime->format('dmY h:i e'));
// result of var_dump is: string(28) "13102015 11:00 Europe/London"
Take aways:
e is the format modifier for the time zone
Conversion of time zones is possible with PHP's DateTime object. Find out what your default time zone is on your current PHP installation to see if you need to convert or not. See information on the date.timezone setting here: http://php.net/manual/en/datetime.configuration.php
Cake 3.0 specific
As Oops D'oh pointed out in the comments there are a lot of CakePHP specific things to know as well. Since he added an excellent part concerning that I suggest you read that as well.
I need to make the date format that I entered into the database look exactly the same as when i view it. Eg. Currently my format is 2013-12-21, but when i view it, it shows 12/21/2013. It's quite confusing because when I edit the date in my form, it's in the 12/21/2013 format and the database wont accept it when i change the date to something like 12/23/2013. Please help. Thanks
(btw, it just auto formatted my date. I didn't even use the <%formatdatetime%> function.)
EDIT: Sorry for the lack of information guys. This is what's happening.
1. I created a form to add date amongst othes to mysql. Eg. Purchase date, item, etc (sql wants it in yyyy-mm-dd format and that's how i enter it.
2. created a view list to select which rows i want to update. (Used
<%=Formatdatetime(f_purchasedate,2)%>
to show date only without time as it was 12/21/2013 12:00:00 AM)
3. created an update form.
Now the problem is it shows the date as 12/21/2013 instead of 2013-12-21. So when i submit the form after altering other fields, it says date error. I have to manually type the format 2013-12-21 for all my dates before i can submit the form.
i'm guessing it has something to do with this line of mine.
purchasedate.Text = ODBCdataset.Tables("tbl_vm").Rows(0).Item(2)
tried this but it doesnt help either...
formatDateTime('purchasedate').Text.ToString("yyyy-MM-dd") = ODBCdataset.Tables("tbl_vm").Rows(0).Item(2)
You can use DATE_FORMAT(date,format)
Select DATE_FORMAT('Your Date Value'),%Y-%m-%d) as Date from table_name
Or
You can pass the value to a variable like below
purchasedate.Text = CType(ODBCdataset.Tables("tbl_vehiclemanagement").Rows(0).Item(2).ToString, DateTime).ToString("yyyy/mm/dd")
Dim date As String = DateTime.Now.ToString("yyyy/mm/dd")
I have a datepicker that I want to display in MM/DD/YYYY. However I'm using a mysql db which wants YYYY-MM-DD. As it stands right now its saving but the day and month are being reversed.
Right now I have an initalizer, date_time_formats.rb which has:
Date::DATE_FORMATS[:default] = '%m/%d/%Y'
Also in my datepicker jscript I have the correct format which I want to display:
$(this).datepicker({"format": "mm/dd/yyyy", "weekStart": 0, "autoclose": true, "startDate":new Date()});
I've tried things like this:
Date.strptime(params[:location], "%d/%m/%Y")
But I get a HashWithIndifferentAccess error.
How can I reformat the date in the params hash prior to assigning to an instance of the model? The reason being it seems to get rejected from the model if the date would be invalid (ex. April 4, 2013 is fine, but April 20, 2013 is not because there is no 20th month). I'm a big time rails novice so maybe I'm wrong but thats how it appears to be working. Thanks!
try the american_date gem located here: https://github.com/jeremyevans/ruby-american_date
Look up the strftime method of the various date classes. The incantation you want is Time.local(params[:location]).strftime('%m/%d/%Y'), hope that helps!
A quick way to sanitize the date to the correct format is to grab it in the controller before it gets saved and use strftime to correct the format. For example:
#model = Model.new(model_params)
#model.date_you_want = #model.date_you_want.strftime('%Y/%d/%m')
#model.save
This saves the date in the correct format. (I'm also using datepicker-boostrap gem)