All,
I've been wracking my brains trying to figure this one out. I need to convert SQL timestamp to a non-standard format that I haven't been able to find an easy way to convert to.
I need to convert:
1900-01-01 00:00:00.000
to
1/1/1900 12:00 AM
I've tried several combos of datepart with casting, but I haven't had much luck. I suppose I'll need to convert a couple of times to get what I want, but I figured I would ask the experts first.
Thanks!
Are you just trying to format a date into a string? If so take a look at this page:
http://www.sql-server-helper.com/sql-server-2008/sql-server-2008-date-format.aspx
Towards the bottom of the page is something that looks just like what you are looking for:
SELECT CONVERT(VARCHAR(20), SYSDATETIME(), 22) --> 06/08/11 1:30:45 PM
Well I ended up finding the desired result with a colleague.
Here is what it ended up being, just in case anyone else needs it.
SELECT CONVERT(VARCHAR(10), EDITDATE, 101) + ' ' + RIGHT(CONVERT(VARCHAR, EDITDATE,100),7) AS ConvertedDate
Related
why this query gives me the wrong output although I am trying to print data between '01-May-2022' and '30-May-2022';
why is this query giving me apr data?
It appears that you are storing your dates as text. You should not be doing this, and the best long term fix is to make datee a proper date column. As a short term fix, you may use STR_TO_DATE:
SELECT datee
FROM customer_shopping_details_tbl
WHERE STR_TO_DATE(datee, '%d-%b-%Y') BETWEEN '2022-05-01' AND '2022-05-30';
Thank you all ....
I did a mistake while saving the date, I had saved the date in the string format. That is the reason that the query does not show proper output
What I learned/point to remember
-MySQL date format is yyyy-mm-dd
-Save your date in the form of date NOT IN String
go through the comments for the better idea
I have saved my data in the form of String so i have fired the following query and is working now
Good evening,
Maybe this could help:
SELECT login,datetime FROM log where datetime between
to_date(’01-jan-2004,’mm/dd/yyyy’) and
to_date(’21-jan-2004′,’mm/dd/yyy’)
order by datetime DESC;
Good day , i'm kind of struggling at the moment and this might be really easy for you , but i'm really new in sql .
I'm trying to change the format of a date from 2021-10-05 to Tue-05-Oct . in a htm file using SQL
I'm struggling cause i do not really understand how to use the convert or formatdate with an object (Select date.birthday as object) .
I'm a bit lost :(
You can format the date using the MySQL DATE_FORMAT() function.
For example:
SELECT DATE_FORMAT(`myDate`, '%a-%d-%b') as textDate from `myTable`
which will return a date in the form Tue-05-Oct.
You could also do this directly in crystal reports by creating a formula field as follows.
totext({ReplaceWithDataFieldToFormat},"ddd-dd-MMM")
Asking for any ideas to convert this kind of date in SQL from May-15-2020 18:03 to 'yyyyMMddHHmiss' or 'yyyyMMdd'.
I am trying this query
select from_unixtime(unix_timestamp('May-15-2020 16:03', 'MM-dd-yyyy
HH:mi'), 'yyyyMMdd') from dual
but it wont work.
Use the right right function STR_TO_DATE, and use a format that matches your date rather than something scraped from a previous answer/blog.
Reference manuals of date and time functions are very useful for solving these basic problems.
I've got this as the select part of my query:
SELECT cast(cast(exp_channel_titles.edit_date as char(14)) as datetime) AS Edit_Date
That takes data from a db in this format 20130501092128 and returns it in this format 2013-05-01 09:21:28
I can only assume it is some kind of magic as i don't fully understand how this works tbh.
But, i need to change the format of the date that it spits out to this format: %d/%m/%Y %k:%i:%s
I can honestly say i have no idea how to do this in that query, i've tried adding it as a param to datetime (is that even a mysql function?!?) but no joy and many other poor attempts that i wont go into.
If anyone can help, i'd be hugely grateful!
MySql automatically converts 20130501092128 to a date and time field, even if it is a VARCHAR or a INT, and you can just use this:
SELECT DATE_FORMAT(exp_channel_titles.edit_date, '%d/%m/%Y %k:%i:%s')
Please see fiddle here.
You can change output format using DATE_FORMAT() function from MySQL. Here is the documentation post about it.
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format
You can change the output format into whatever format you want, but if you recieve that data into an application, modifies it and return that data to server (editing a row for example). Remember to reformat it into a valid date for MySQL.
If you dont know how to do it, just have to do this into your query:
SELECT DATE_FORMAT(cast(cast(exp_channel_titles.edit_date as char(14))
as datetime), '%e/%m/%Y %k:%i:%s') AS Edit_Date
I have Database with date field.
I see the time like: 1900-01-01 13:38:00.000
How i can format it like: 13:38 ?
SELECT convert(varchar, getdate(), 108) outputs as hh:mm:ss.
If you are using SQL server 2008 then,
Suppose your column name is XTime which is holding time in HH-MM-SS.ms formate. If we want to retrive time in HH-MM-SS format then write following query,
Select ID, XDate, Convert(Time(0),XTime,0) -- For HH-MM-SS format
Try this:-
RIGHT(CONVERT(VARCHAR,'DATE',100),7)
For non-military time.
I know I am late. This has already been answered by #Yes - That's Jake. It works perfect. But to help you more, I have a cheat sheet link so that you can write it in any format.
You can visit: Date and Time conversions using SQL cheat sheet
You will find a list of codes and the format that #Yes - That's Jake mentioned in his answer.