I have a datetime field .for e.g. 2013-08-22 12:00:00 AM. I want to concatenate the year and month and i want the output as 201308.
When i try year (datetime_field)+month(datetime_field) what i get get is 2013+08=2021 .. i.e it adds instead of conactenating. Can someone pl tell how to get the output as 201308?
something more like
str(year(datetime_field)) + str(month(datetime_field))
should give you what you want.
the str function converts your numeric data to a string, setting up the + to be a string-concatenation operation instead of an arithmetic-addition operation.
Related
I have to create a derived column to upload a date in OLEDB destination because my source file doesn't contain this date. The date i want to get through derived column is last day of last month. Does anyone know how to get it?
Try the following expression, just substract the current day from the current date using DATEADD Function.
DATEADD("d", -DAY(GETDATE()), GETDATE())
If you want to remove time you have two choices:
convert to string
LEFT((DT_STR,50,1252)DATEADD("d", -DAY(GETDATE()),GETDATE()),10)
convert to string then to date (it will generate time 12:00 AM)
(DT_DATE)LEFT((DT_STR,50,1252)DATEADD("d", -DAY(GETDATE()),GETDATE()),10)
The simplest way if you don't need time is :
(DT_DBDATE)(DATEADD("d",-DAY(GETDATE()),GETDATE()))
How I can get current date on YYYY-MM-dd (2016-10-28) format in MDX?
Format(Now(),'YYYY-MM-dd')
Doesn't work.
EDIT:
I've just check that MDX convert my YYYY-MM-dd format to yyyy-MM-ddT00:00:00 (I compare my date with current date) so I need something like:
Format(now(), "yyyy-MM-ddT00:00:00")
Never even heard of MDX but with a quick Google search it seems you should use the following format:
Format(Now(),'yyyy-MM-dd')
Notice the lower case y for year.
This information was deduced from here.
After Edit
The new format you want would therefore be:
Format(Now(),'yyyy-MM-ddT00:00:00')
I am relatively new to Stata. I have a string variable time that records year and month in the following format:
2000m1
2000m2
2000m3
...
2015m12
I would first like to create a date variable that looks identical (but it has to be in the date format) to the above. Second, I would like to separate year and month components into two different variables, and third, I would like to rename the month component to January, February, etc.
For the first task, the command date = date(time, "YM") returns an empty variable and I can't figure what I am doing wrong.
The function date() yields daily dates, not monthly dates or any other kind of date that isn't a daily date. See its help (help date()) which begins
date(s1,s2[,Y])
Description: the e_d date (days since 01jan1960) corresponding to s1
based on s2 and Y
s1 contains the date, recorded as a string, in virtually
any format. Months can be spelled out, abbreviated (to
three characters), or indicated as numbers; years can
include or exclude the century; blanks and punctuation are
allowed.
s2 is any permutation of M, D, and [##]Y, with their order
defining the order that month, day, and year occur in s1.
##, if specified, indicates the default century for
two-digit years in s1. For instance, s2="MD19Y" would
translate s1="11/15/91" as 15nov1991.
In essence, it needs to be told a day, month and year. You supplied a month and year, and date() won't (can't) play.
As documented at the same place, daily() is a synonym for the same function and it's good practice to use it to remind yourself (and readers of your code) of what it does.
Correspondingly, monthly() provides an easier solution to create a monthly date from string input than in your own answer. Try out solutions using display (di is allowed) on simple cases where you know the right answer.
. di monthly("2000m1", "YM")
480
. di %tm monthly("2000m1", "YM")
2000m1
Reading the documentation is crucial here. See help datetime for a start. There is a lot to explain as dates come in many different forms, but it's all documented.
See also help datetime_display_formats for how to display dates differently. (No "renaming" is involved here.) For example,
. di %tmMonth_CCYY monthly("2000m1", "YM")
January 2000
I figured out the first part. I post the answer to here for anybody who needs a reference:
gen date = ym(real(substr(time, 1,4)),real(substr(time,6,2)))
format date %tm
Try this code may be it works for you
string Date1 = String.Format("{0}", Request.Form["date"]);
string Date2 = String.Format("{0}", Request.Form["date1"]);
Date1 = DateTime.Parse(Date1).ToString("yyyy-MM-dd");
Date2 = DateTime.Parse(Date2).ToString("yyyy-MM-dd");
I am using server time for one of my process. For that I am taking date and time using postgresql. The time format I want is 2 digit day,month,hour,minute,second and 4 digit year (eg: 05/01/2015 16:05:30). I am using SELECT to_char(now()::timestamp,'DD/MM/YYYY HH24:MI:SS') I want to make sure that the number of digits for each will be as like I want. Because its very important for my processing. I have refered the following link Link. There it is saying, day of month (01-31) for DD's decription. Is there any possibility to get day as 1 instide of 01
Feel safe.
The table ad your link (http://www.postgresql.org/docs/9.4/static/functions-formatting.html#FUNCTIONS-FORMATTING-DATETIME-TABLE)
is right.
Numbers in date converted with to_char, are 0 padded.
Is there any possibility to get day as 1 instide of 01
You can use regular expression to remove leading 0:
select regexp_replace(to_char(now()::timestamp,'DD/MM/YYYY HH24:MI:SS'), '^0(\d)', '\1', 'g');
I could use some help deriving a year quarter from a text string that represents a date. I have a string, say '20121230', to represent 12/30/2012. Somehow, someway, I need to convert this value into '4Q12.' I get stuck after converting the 20121230 into a date:
CONVERT(date,datestringfield,111)
I need help deriving the quarter and year from this date and then converting the quarter and year to a string format 4Q12. Any help would be greatly appreciated
If you are using SQL Server, then the particular format of datestringfield can be used as a date unambiguosly. So, you can do:
SELECT DATENAME(QUARTER,datestringfield) + 'Q' +
RIGHT('00'+DATENAME(YEAR,datestringfield),2)