how to write Oracle Function For Convert Date to persian (jalali) - database

i want to convert date to Persian date (jalali) in oracle Database
there is any function ?

You can use this statement:
select to_char(hiredate,'yyyy/mm/dd','nls_calendar=persian') from emp
hiredate is a date field, with this select hiredate is displayed in persian

First of all you must set nls_calendar to Persian like below:
Alter session set nls_calendar=persian;
Now you can change format of date like below:
Select to_char(sysdate,'yyyy/mm/dd') from dual;

Related

I need to convert date (25/01/2019) to Jan'19 format in sql server

I need to convert the contents of a DATE colum and store it in another column.
Example
(25/01/2019) to Jan'19.
This following option is not a good one considering performance but you can get your desired result-
SELECT
REPLACE(CAST(FORMAT(CONVERT(DAte,'25/01/2019',103), 'MMM-yy') AS VARCHAR),'-','''')
Use of FORMAT is to get value is desired format.
if you have hardcode date you can use this one :
SELECT
REPLACE(FORMAT(CONVERT(Date,'25/01/2019',103), 'MMM-yy'),'-','''')
if you have column in database then you can use :
SELECT REPLACE(FORMAT(DateColumnHere, 'MMM-yy') ,'-','''')
FROM Table1
A date type column has no format but we can change the display format by converting it to a string. In your case, [myDate] should be a string type column such as varchar, and we'll cast it to date before converting the display format. So consider :
with tab([myDate]) as
(
select '25/01/2019'
)
select convert(varchar,
cast(concat(substring(myDate,7,4),'-',
substring(myDate,4,2),'-',
substring(myDate,1,2)) as date) ,6)
as [myDate]
from tab;
myDate
---------
25 Jan 19
Demo

Alter view sql date

I have an assignment to change the existing date format in an existing T-SQL view statement. Where the date format is set to YYYY-MM-DD 00:00:00.000 the task is to change is to ALTER VIEW to MM-DD-YY formatting. I'm lost on this one.
USE Ch8_simpleco
ALTER VIEW
AS invoice
SELECT INV_DATE
SET INV_DATE (MMDDYY)
FROM dbo.v_cust_invoices;
You are probably looking for something like this:
ALTER VIEW invoice
AS
SELECT COVERT(char(8), INV_DATE, 10) -- will get you dd-MM-yy (no century!)
FROM dbo.v_cust_invoices
You can use FORMAT() like this:
ALTER VIEW invoice
AS
SELECT FROMAT(INV_DATE,'MM-dd-yy') as INV_DATE
FROM dbo.v_cust_invoices

sql server date stored in table comparing with the system date

really struggling to convert the below date format 10.11.2013 in the format
of the system date.
I have a request to compare column data with the system date.
In the column the date is storing as DD.MM.YYYY
Or we need to convert system date (getdate()) to the date values stored in the database table.
Thanks in Advance
Regards,
Dev
try this:
convert system date (getdate()) to the date values stored in the
database table.
Gives formats as DD.MM.YYYY
select CONVERT( CHAR(10),GETDATE(),104) -- outputs 11.09.2014
with Your Column
select CONVERT( CHAR(10),MyColumn,104)

SQL Server: How to query date in a certain format

I am pretty new to SQL and hope someone here can help me with the following:
I have a table in SQL Server with one column storing dates and I have a simple stored procedure to select data from this table.
Currently it fetches the date including hours and minutes.
How can I achieve that it fetches the date in format yyyy-mm-dd (without the hours and minutes) ?
My column is called "logDate" and my table is called "logTable".
Thanks for any help with this, Tim
If you only want to store the date, convert the column to a date type, not a datetime.
If you want to keep the date and time in the data, but just display the date
select convert(date, logDate) from logTable
If you want to return the date as a string, use convert
select convert(varchar(10), logDate, 120) from logTable

T-SQL - changing datetime to date data type?

I have a column BirthDate in a table that is using the datetime data type. Currently, the values resemble the format 1987-12-30 00:00:00.000.
I would like to update all the rows of this table, changing them to the following format with the date data type: 1987-12-30
I can run a SELECT...
SELECT CONVERT(date, BirthDate) FROM CUSTOMERLIST
But this is only affecting the display. I would like for it to update the entire column and also change the data type of that attribute as well. Any assistance would be greatly appreciated!
You will need to ALTER the table:
ALTER TABLE CUSTOMERLIST ALTER COLUMN BirthDate date not null
See Sql Fiddle with demo

Resources