how to format date using XQuery - xquery

i have date showing like the following
01-Nov-2012 12:00:00 AM
and i want to show the if the date is like above than
01-Nov-2012
this comes for few data only not for all,
How to do this in Xquery.
Please help
Regards

This will work:
fn:replace("01-Nov-2012 12:00:00 AM", "\s.*", "")
It replaces the space and everything after with the empty string.

You could use either:
tokenize(/test,' ')[1]
or
substring-before(/test,' ')
With /test being replaced with the appropriate path to the date.

It is so simple.
convert(VARCHAR(10),datetoformate,106)
thats it

Related

If else condition works with days?

I required date as mentioned below in if condition.
if day('2019-12-23') <=15 then '2019-11-16' else '2019-12-01'.
I have tried writing codes in R, but output is not correct.
Codes
ifelse(day(Sys.Date()) <=15,
(ymd(Sys.Date()-day(Sys.Date()-1)) %m-% months(1))+15,
ymd(Sys.Date()-day(Sys.Date()-1)))
Output
18231
Required Output
2019-12-01
Please help me with the solution.
Got the solutions thanks. forgot to convert into character.
updated query
ifelse(day(Sys.Date()) <=15,
as.character((ymd(Sys.Date()-(day(Sys.Date()-1))) %m-% months(1))+15),
as.character(ymd(Sys.Date()-(day(Sys.Date()-1)))))

R - String to Date Conversion

Say I have a string of date like "3/23/2016" and just want to change the format to 3/23/2016. I try:
as.Date("3/23/2016, "%m%d%Y") but keeps giving me NA, as well as trying other methods. Anyone know a easy/fast way to do this? 03/23/2016 is ok too.
Try this:
b=as.Date(a, "%m/%d/%Y"),
It will give you the result then
Try:
Class(b)
to find the format.
Hope this helps :)
Another option is lubridate
library(lubridate)
mdy("3/23/2016")
#[1] "2016-03-23"

Custom Expression Function: ParseDateTime

Given a DateTime of
10-OCT-2015 07:10 PM
How can one convert this? I've got the first part correct but it's the Time I'm having difficulty with.
ParseDateTime([column name],"dd-MMM-yyyy hh:mm")
How can AM/PM be represented?
Figured it out!
ParseDateTime([Diary Date],"dd-MMM-yyyy hh:mm tt","en-US")

C# format of date issue

My problem: I need to get date format as "mm/dd/yyyy"
Scenario:
I have declared DateBirth as nullable DateTime.
The value I get when I use:
AdvancedObj.DateBirth .Value.ToString()
is: "13/03/2013 00:00:00"
The value I get when I use
AdvancedObj.DateBirth .Value.ToString(CultureInfo.InvariantCulture)
is :"03/13/2013 00:00:00"//This is roughly correct but, I do not need 00:00:00
I have tried this as well, but the format is correct and value is incorrect.
AdvancedObj.DateBirth.Value.ToString("dd/mm/yyyy",CultureInfo.GetCultureInfo("en-Us"))
**"13/00/2013"**
Can anybody point me, what am I missing?
Use the right format string for months - it is MM. mm is for minutes:
AdvancedObj.DateBirth.Value.ToString("MM/dd/yyyy",CultureInfo.InvariantCulture)
Also, order them correctly as above - if you want months before days, use MM/dd/yyyy, if the other way around, dd/MM/yyyy.
I suggest you take a good long read of Custom Date and Time Format Strings on MSDN.
Month are 'M'. 'm' is for minutes.
"dd/MM/yyyy"

Regular Expression for Date Format : dd-mm-yyyy

I want to check the date which must be in the format dd-mm-yyyy using a regular expression, and it also must check the leap year dates.
I am using RegularExpressionValidator for checking the date.
try this. It works for me!
ValidationExpression="(^((((0[1-9])|([1-2][0-9])|(3[0-1]))|([1-9]))-(((0[1-9])|(1[0-2]))|([1-9]))-(([0-9]{2})|(((19)|([2]([0]{1})))([0-9]{2}))))$)"
Try this regular expression-
^(((((0[1-9])|(1\d)|(2[0-8]))-((0[1-9])|(1[0-2])))|((31-((0[13578])|(1[02])))|((29|30)-((0[1,3-9])|(1[0-2])))))-((20[0-9][0-9]))|(29-02-20(([02468][048])|([13579][26]))))$
Got it from Here
This regex also handles leap year:
^(((0[1-9]|[12]\d|3[01])/(0[13578]|1[02])/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)/(0[13456789]|1[012])/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])/02/((19|[2-9]\d)\d{2}))|(29/02/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$
Matches
[29/02/2000], [30/04/2003], [01/01/2003]
Non-Matches
[29/02/2001], [30-04-2003], [1/1/1899]
You can also check this link out: http://www.codeproject.com/KB/aspnet/LengthValidation.aspx
You can javascript to check leap year for more info
isLeap = new Date(year, 1, 29).getMonth() == 1
Regular Expression
^(?:^(?:(?:(?:(?:(?:0?[13578]|1[02])/31)|(?:(?:0?[13-9]|1[0-2])/(?:29|30)))/(?:1[6-9]|[2-9]\d)\d{2})|(?:0?2/29/(?:(?:(?:1[6-9]|[2-9]\d)(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))/(?:0?[1-9]|1\d|2[0-8])/(?:(?:1[6-9]|[2-9]\d)\d{2}))$)$
These allow but do not require a leading zero in single-digit months/days. If you don't want that, replace all instances of 0? with 0.
You could use a CustomValidator and have the client-side validation be simple and on the server-side use a DateTime.TryParse to get a definitive validation. Although I suspect you don't need your code to work all the way to the year 9999 (no, I couldn't immediately see if the supplied regexes work that far into the future).
from Microsoft DN but modified to work with years both 20xx and 19xx to used as DOB
^(((((0[1-9])|(1\d)|(2[0-8]))/((0[1-9])|(1[0-2])))|((31-((0[13578])|(1[02])))|((29|30)-((0[1,3-9])|(1[0-2])))))/((((20[0-9][0-9]))|(29-02-20(([02468][048])|([13579][26]))))|(((19[0-9][0-9]))|(29-02-19(([02468][048])|([13579][26]))))))$
for dd/MM/yyyy formate
(((0|1)[0-9]|2[0-9]|3[0-1])\/(0[1-9]|1[0-2])\/((19|20)\d\d))$

Resources