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'
Related
Sorry about the bad title, I didn't exactly know how to phrase that any better. I'm going to try to explain what I need as best as possible.
I'm currently making a Task Manager (a ToDo list) in Javascript where you can create tasks, set a schedule for them and then you would have a list with all the tasks that you need to do and the respective schedule of each task (beginning and ending date).
I'm using Angular.js and Angular Material to do my UI. I have the Angular Material's datepicker. This is the code I use to get the date value:
angular.module('KBTM_App', ['ngMaterial']).controller('AppCtrl', function($scope) {
$scope.myDate1 = new Date();
...
// This is where I get the date value
var initial_date_1 = angular.element(document.querySelector('[ng-controller="AppCtrl"]')).scope().myDate1;
The problem is that this datepicker is returning the date in this format:"2016-04-29T08:36:10.027Z", which I don't want. I want a more normal format, like "DD-MM-YYYY".
I tried converting the date format with Moment.js, but that didn't work. Here's the code I used for that:
var initial_date = moment(initial_date_1, "YYYY-MM-DD'T'HH:MM:SS.SSS'Z'").format("DD-MM-YYYY");
And then I would store that date in the localStorage:
// Get the other dates already in the list
var initial_dates = get_initial_dates();
// Adds the new date to that list
initial_dates.push(initial_date);
// Stores those dates in the localStorage
localStorage.setItem('initial_date_db', JSON.stringify(initial_dates));
With that code I get "Invalid date" when trying to add a new task to the task list.
Sorry for the long post!
Thanks to whoever can help me.
You can convert the date format in html using angular material datepicker by using following code.
data-ng-value="myDate1 | date : 'shortDate'"
Use the angular date filter to format the date. Refer the link angular date
var initial_date = $filter('date')($scope.myDate1, "dd-MM-yyyy");
Inject the $filter in your controller main module.
Best way to handle dates is to use momentjs and there is a special AJS Directive available. angular-moment
You can check [momentjs][2] offical docs for detailed info. You have to add angular-moment as dependency injection to use moment easily. https://github.com/urish/angular-moment#instructions-for-using-moment-timezone-with-webpack
So I receive my app data via an API returning JSON data. With that, my time stamps are always returned with an undesirable look. Always like this:
2013-11-25T12:44:02
So I am using angular to build my app and couldn't see a way to format this with simply returning something like:
<div>
<p ng-repeat="date in ppt.Alerts | filter:{type: DenialStatement}"><span>{{date.date}}<span> <span>{{date.descr}}<span></p>
</div>
In this case, date is that time property. So I was figuring within my html, if I could benefit from using moment.js to format this or a better way to do this across the board.
Can anyone here assist with this?
Thanks much.
Your text is string representation of date object, you can assign
date.date = new Date(input)
during data retrieval this will work fine. And you can print directly angular built in date filter
<span>{{date.date|date :'dd/MM/yyyy'}}<span>
or any format you prefer.
Angular has built in date filter
{{date.date | date : format : timezone}}
See date filter docs for format and timezone usage
I am working on a parse (Facebook) app. I have a table however I want to be able to get the expired events (aka events that occur after some date). What is the best way to do this. I didn't see a date documentation with Parse.
My thought from dynamo experience was to simply save it and compare the values but this is costly. Is there a more efficient way?
Any ideas / anyone done this?
Thanks!
Just use the greaterThan, greaterThanOrEqualTo, lessThan and lessThanOrEqualTo methods on Parse.Query, and pass in date objects.
I.e.
var query = new Parse.Query("Event");
query.lessThan("eventDate", new Date());
This query will get you all objects from the table "Event", whose column "eventDate" (a Date column) contains a date that is before the current date.
I have searched for this but couldn't find anyone trying to do what i am doing with jqGrid formatters.
I have a date which I am trying to parse which is not in a jqGrid table, but I am using jqGrid on the site elsewhere and am hoping to parse this date using jqGrid's date parser instead of having to write a seperate method.
I have been messing around with the jGrid object but I need a little help with this.
My date format is ISO8601Long i.e. 2013-11-17T09:00:00
First, I am ensuring the date formats in the formatter are the ones i wish to use:
jQuery.jgrid.formatter.date.srcformat = 'Y-m-d H:i:s';
jQuery.jgrid.formatter.date.newformat = 'j/m/Y g.ia';
Next, I call the jQuery.jgrid.parseDate method in an attempt to parse the date.
jQuery.jgrid.parseDate(0, 0, '2013-11-17T09:00:00');
I am not sure what the first two arguments are, but they look like they might accept a srcformat and newformat. Either way, they don't format as I would expect. There is a fourth too, but this seems to only accept an object.
This leaves me with 2013-11-17GMT09:00:00. While this is a bit easier to understand, it is not in the format I would be expecting. I presume I have missed a step or somehow need to call the formatter after this.
Any pointers would be great.
Thanks,
Dale
The correct usage of parseDate would be the following:
var parsedData = $.jgrid.parseDate("Y-m-d H:i:s", "2013-11-17T09:00:00", "j/m/Y g.ia");
or
var parsedData = $.jgrid.parseDate("ISO8601Long", "2013-11-17T09:00:00", "j/m/Y g.ia");
You can use alternatively Globalize jQuery Plugin.
I'm trying to convert an HTML table to Excel in Javascript using new ActiveXObject("Excel.application"). Bascially I loop through table cells and insert the value to the corresponding cell in excel:
//for each table cell
oSheet.Cells(x,y).value = cell.innerText;
The problem is that when the cell is in date format of 'dd-mm-yyyy' (e.g. 10-09-2008), excel would read as 'mm-dd-yyyy' (i.e. 09 Oct 2008). I tried to specify NumberFormat like:
oSheet.Cells(x,y).NumberFormat = 'dd-mm-yyyy';
But, it has no effect. It seems that this only affect how excel display the value, not parse. My only solution now is to swap the date like:
var txt = cell.innerText;
if(/^(\d\d)-(\d\d)-\d\d\d\d$/.test(txt)) txt = txt.replace(/^(\d\d)-(\d\d)/,'$2-$1');
But, I'm worrying that it is not generic and a differnt machine setting would fail this.
Is there a way to specific how excel parse the input value?
You can avoid Excel's date parsing by entering the data using its native 'serial' date format. e.g '22nd Dec 08' is 39804 as an Excel serial date. (See here for a good explanation of these)
Then format the cell as you did before.
determine what culture-neutral date formats excel supports
use javascript to parse your date string and output in the an appropriate format
I don't know what formats excel supports but you'd want something like .net's round trip or sortable formats, where it will always be read consistently.
for #2, if you can trust javascript to construct an appropriate date from whatever string you feed it that's fine. if you're not sure about that you might look at a library like datejs where you can be more specific about what you want to happen.
Instead of
oSheet.Cells(x,y).NumberFormat = 'dd-mm-yyyy';
set this:
oSheet.Cells(x,y).NumberFormat = 14;
In Vbscript, we use to resolve this by
If IsDate ( Cell.Value ) Then
Cell.Value = DateValue ( Cell.Value )
End If
Maybe, In java script also you need to play with same approach.
I've tried your code but at end of the process, I re-applied format to the columns containing dates. It works fine, no matter what local language you have configurated yor machine.
Being my excel object defined as 'template', as soon as I got it data filled, I applied (just for example):
template.ActiveSheet.Range("D10:F99").NumberFormat = "dd/MMM/yyyy;#";
best regards