After googling around, I cannot find a way to create a new table with a DATETIME column with the default format set to 'DD-MM-YYYY HH:MM:SS'
I saw a tutorial in which it was done in phpmyadmin so I suspect that I could use mysql via command line and achieve the same thing when creating my new table with
CREATE TABLE ()
Thank you in advance
"MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format."
This is from mysql site. You can store only this type, but you can use one of the many time format functions to change it, when you need to display it.
Mysql Time and Date functions
For example, one of those functions is the DATE_FORMAT, which can be used like so:
SELECT DATE_FORMAT(column_name, '%m/%d/%Y %H:%i') FROM tablename
Use DATE_FORMAT function to change the format.
SELECT DATE_FORMAT(CURDATE(), '%d/%m/%Y')
SELECT DATE_FORMAT(column_name, '%d/%m/%Y') FROM tablename
Refer DOC for more details
As others have explained that it is not possible, but here's alternative solution, it requires a little tuning, but it works like datetime column.
I started to think, how I could make formatting possible. I got an idea. What about making trigger for it? I mean, adding column with type char, and then updating that column using a MySQL trigger. And that worked! I made some research related to triggers, and finally come up with these queries:
CREATE TRIGGER timestampper BEFORE INSERT ON table
FOR EACH
ROW SET NEW.timestamp = DATE_FORMAT(NOW(), '%d-%m-%Y %H:%i:%s');
CREATE TRIGGER timestampper BEFORE UPDATE ON table
FOR EACH
ROW SET NEW.timestamp = DATE_FORMAT(NOW(), '%d-%m-%Y %H:%i:%s');
You can't use TIMESTAMP or DATETIME as a column type, because these have their own format, and they update automatically.
So, here's your alternative timestamp or datetime alternative! Hope this helped, at least I'm glad that I got this working.
i have used following line of code & it works fine Thanks.... #Mithun Sasidharan
**
SELECT DATE_FORMAT(column_name, '%d/%m/%Y') FROM tablename
**
I'm pretty certain that you can't change the datetime format in mysql. The phpmyadmin setting is probably applying a custom format as it reads the datetime (using DATE_FORMAT or something from php). It shouldn't matter what format the database uses, format in the application to display it as you wish.
Date formatting is a pretty common task. I typically like to abstract it out into internationalization code or, if you don't need to deal with i18n, into a common date utility library. It helps keep things consistent and makes it easier to change later (or add i18n support).
No you can't; datetime will be stored in default format only while creating table and then you can change the display format in you select query the way you want using the Mysql Date Time Functions
This cannot be done for the table; besides, you even cannot change this default value at all.
The answer is a server variable datetime_format, it is unused.
Dim x as date
x = dr("appdate")
appdate = x.tostring("dd/MM/yyyy")
dr is the variable of datareader
try this:
DATE NOT NULL FORMAT 'YYYY-MM-DD'
I build android app and in my app have some search function with input type date. I try used parse input date from 2017-5-10T17:00:00.000Z to 2017-5-10 with moment.angular. in search function work but it make my app error and wan't move to anothe page just stact in search page. I don't know where is error
this my html
<label class="item item-input">
<span class="input-label">Start</span>
<input type="date" ng-model="trip.start">
</label>
and this my controller
$scope.trip.start = moment($scope.trip.start).format("YYYY-MM-DD");
and i add some srcin my index
<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.5.1/moment.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.min.js"></script>
please help me solve this problem
thanks
moment($scope.trip.start).format("YYYY-MM-DD") is not in Angular date object format.
As a work around you can use moment($scope.trip.start)._d.
So your code would be
$scope.trip.start = moment($scope.trip.start)._d;
the issue is mostly with date format. The date given is 2017-5-10T17:00:00.000Z which is of format YYYY-M-DD and not a standard ISO format, hence moment is mostly not able to parse it. As per ISO the date should be 2017-05-10T17:00:00.000Z
Note: .format has nothing to do with input format, its for output.
Note: Cant comments hence adding this to answer: the order of JS is correct. moment is independent of angular hence it does not need to appear after angular.
EDIT
You can try below to get the date
moment(Date.parse($scope.trip.start)).format("YYYY-MM-DD");
I expect that stringResult will give me an output that corresponds to the specified format, but it always looks like YYYY-MM-DD HH:MM
Full code here.
For example, I've tried the following config:
{
view:"datepicker",
stringResult:true,
format:"%Y-%F-%d"
},
But the output is still the same. So, is it a bug? Or am I doing something wrong? Thank you in advance!
[Updated]
As mentioned by Loj, I agree with it. Thus, there are 2 solutions possible:
1. Custom Format
The format property you have used sets a date format to display in the datepicker field. So, it is just the display format and it is not actually formatted. Hence, the stringResult returns date as string with the default format.
In order to get the custom date in the output, you are required to add your custom format which will convert the date in the desired format.
var format = webix.Date.dateToStr("%Y-%F-%d");
Check the snippet here.
2. Using getText()
Using stringResult property in the control's configuration makes the getValue method to return raw unformatted value. Hence, instead you should use the getText() as
$$("custom").getText();
in your code to get the formatted output via stringResult.
I'm trying to populate a form on a site with values passed through GET. The two fields I'm having trouble with are input tags that are of type type="date" or type="time". Chrome has this nice feature that gives you a drop down calendar to select a date:
Chrome also does something similar for the Time field. The problem is that it doesn't like javascript that tries to populate those types of form fields. I pass GET information like so:
The reason the date is formatted like this is because that's what the back-end requires (not what I'm working on) and the date comes directly from the back end code.
I have a function that auto-populates document.$_GET as an array with all passed values from GET. I also have date.js included, which allows me to use the Date.parse functionality and some other stuff. I pass it through javascript like this:
if(document.$_GET['time']!=undefined)
document.getElementById('time').value=document.$_GET['time'];
if(document.$_GET['date']!=undefined){
var date = new Date();
date = Date.parse(document.$_GET['date']);
alert(date.toString('MM-dd-yyyy')); // <-- Debugging
document.getElementById('date').value = date.toString('MM-dd-yyyy'); //WHY WON'T YOU WORK!?
}
On Safari I get what I expect to get:
With Chrome I'm left with empty form fields:
I'm stumped and not sure how to remedy this. I need Chrome to autofill similar to how Safari does.
Google Chrome is strict about the format of the Date.
The date works with the following format, YYYY-MM-DD.
The time works with military time. (24h clock)
Here's a sample,
http://jsfiddle.net/vFnxw/2/
$("#date").attr({
value:"2012-09-28"
})
$("#time").attr({
value:"23:59:59"
})
Here are the sources
http://dev.w3.org/html5/markup/input.date.html
http://dev.w3.org/html5/markup/input.time.html
I am trying to use the date.format and getting an error that format is not a recognized method. I tried to use thesame in new solution, and I'm getting a correct result. Any idea why .format method is not working? These both are in Javascript.
Assuming you are talking about Date type...
It is clear why format method is not working - because there is no such method on Date object.
It is less clear why/when it would work - most likely you are using some script library that modifies Date object to have format method.
But if you are talking about some other type - format function may be present (or added) to any object and it is not possible to suggest anything without code...
I.e. custom object with format function:
var date = { format:function() {alert("Hi");}};
date.format();