I am new to ruby and i need help to convert a string of format "dd.mm.yyyy" to date time.
Thanks in advance!
Date.strptime('03.02.2001', '%d.%m.%Y')
UPDATE:
This will return a Date object
As David rightfully stated below:
DateTime.strptime('03.02.2001', '%d.%m.%Y')
will give you a ruby DateTime object.
Related
Trying CONVERT()
Trying STR_TO_DATE()
Trying CAST() - neither DATE or DATETIME work
Trying CAST(STR_TO_DATE())
Hi, I cannot figure out what I'm doing wrong with trying to convert my varchar column Procedure_Date containing a string in the dd/mm/YYYY hh:mm:ss format. I am trying to extract just the date from this string but I seem to be cursed. Using MariaDB and have gone through all the docs there. Greatly appreciate any advice!
You can use cast
SELECT Procedure_Date, CAST(STR_TO_DATE(Procedure_Date, '%d-%m-%Y') AS DATE) FROM uniTable5;
Use: DATE('YOUR DATETIME')
EXAMPLE: DATE('2022-04-25 14:50:01')
OUTPUT: 2022-04-25. Result in DATE.
I have a date in string variable strOrderEndDate which looks like this 8/14/2015.
I would like to convert it to 2015-08-14.
How do I do this in vb.net?
I tried strOrderEndDate.ToString(yyyy mmmm dd) but its not working
As the comments indicate, you first need to convert the string to a date using CDate. Then you can use the .ToString method on the new date type variable to format the output as desired:
Dim strOrderEndDate As String = "8/14/2015"
Dim datOrderEndDate As Date = CDate(strOrderEndDate)
MsgBox(datOrderEndDate.ToString("yyyy-MM-dd"))
...or as Plutonix recommends, you can use DateTime.Parse to perform the conversion. He's pretty smart so if he says it's better, then it's better.
Dim datOrderEndDate As Date = DateTime.Parse(strOrderEndDate)
i have a string which has a value of "08-06-2008". I want the result to look like "08-06-08". Is there a way to do this? I've tried CDate but that only gives me 8/06/2008 which doesnt resolve the issue.
Parse it to Date and back to string:
Dim dt As Date = Date.ParseExact("08-06-2008", "MM-dd-yyyy", CultureInfo.InvariantCulture)
Dim result As String = dt.ToString("MM-dd-yy", CultureInfo.InvariantCulture)
Since that is a normal format you could also omit the format string and use Date.Parse directly:
Dim dt As Date = Date.Parse("08-06-2008", CultureInfo.InvariantCulture)
I have used CultureInfo.InvariantCulture to avoid localization issues, normally your current culture is used in Parse/ParseExact and ToString.
See: Custom Date and Time Format Strings
Firstly, avoid CDate. It is a hangover from VB6, and is almost certainly less efficient than using the .net equivalent.
The following should give you the right answer:
string value = DateTime.ParseExact("08-06-2008", "dd-MM-yyyy").ToString("dd-MM-yy")
Note that your existing date format is ambiguous, so I've been unable to tell if you're meaning the 6th of August or the 8th of June - this is why I've used ParseExact over Parse. ParseExact is also slightly more efficient, as it tells the framework which format to use, rather than it having to guess.
Try this
Dim FormatString As String = ""
Dim SampleDate As DateTime
SampleDate = Now()
FormatString = Format(SampleDate,"dd-MM-yy")
I'm using vb.net 2005.
How do convert this date / time 21/08/2008 00:21:00 to a DateTime object ?
You can use a custom date time format string in conjuction with DateTime.ParseExact or DateTime.TryParseExact.
Dim dateTime as DateTime = _
DateTime.ParseExact("21/08/2008 00:21:00", "dd/MM/yyyy HH:mm:ss", _
CultureInfo.InvariantCulture)
Dim d as DateTime = DateTime.Parse("21/08/2008 00:21:00")
Console.WriteLine(d)
produces this:
21/08/2008 12:21:00 a.m.
If you want to be sure to parse that format correctly, you should use DateTime.ParseExact with a custom format string matching your pattern (e.g. dd\/MM\/yyyy HH:mm:ss).
I'm using vb.net not c#, my solutions a bit old, but it works
Dim d1 As Date
d1 = CDate("21/08/2008 00:21:00")
Console.WriteLine(d1)
I have a series of dates formatted as:
26/03/1992
12/06/2010
13/01/1995
etc... it's in DD/MM/YYYY. I need to find the day like "Tuesday", "Monday" etc out of them.
I know I need to parse the date or something but I'm unsure how to go about this.
You can cast it as a DateTime and use the DayOfWeek property which returns a DayOfWeek enumerator.
Not sure in VB.NET but in C# it's like
DateTime.Now.DayOfWeek or DateTime.Parse(theDateString).DayOfWeek
You want to look at the format strings for the ToString method. MyDate.ToString("dddd") will get you what you want.
The best thing it works for me in vb 2010 is
I add timer and enabled it then i put it like that
Label6.Text = Format(Now, "dddd/dd")
"dd" gives me the day Num.
"dddd" gives me the name of the day
DateTime.Parse("2010/12/31").dayofweek
Convert the date into a date datatype, then use the format function. This displays monday:
Dim d As Date
d = "11/23/2009"
MsgBox(Format(d, "dddd"))
You could also get a numeric day of the week using d.DayOfWeek.
'Declaration
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Class ArgumentOutOfRangeException
Inherits ArgumentException
Implements ISerializable
'Usage
Dim instance As ArgumentOutOfRangeException
Have a look at the documentation of the DateTime members Parse, TryParse, DayOfWeek and ToString.
Try
dateValue.DayOfWeek.ToString()
In VB try this:
DateTimePicker1.Value.DayOfWeek.ToString
It works
MsgBox(Now.Date.DayOfWeek.ToString)