How to covert mm/dd/yyyy to dd/mm/yyyy - asp.net

I have a textbox in which date is in format mm/dd/yyyy. I want to convert it from mm/dd/yyyy to dd/mm/yyyy in asp.net with vb to a DateTime variable.

DateTime.ParseExact("12/21/2008", "MM/dd/yyyy", CultureInfo.InvariantCulture).ToString("dd'/'MM'/'yyyy")
Update: Given that you want to have a DateTime in the end, you can just parse the original format:
DateTime.ParseExact("12/21/2008", "MM/dd/yyyy", CultureInfo.InvariantCulture)
The date formats are of use only when presenting the date as a string (internally the date does not have a format; it's just a number). If you want to store it in a DateTime all you need to bother about is to interpret the input correctly.

If you are dealing with a DateTime object you convert can like this:
yourDateTime.ToString("dd/MM/yyyy"))

Related

Convert date to other format other than YYYY-MM-DD

I need to convert input date coming in format YYYY-MM-DD. First I convert it into char by following:
TO_CHAR(<date_column>,'YY/MM/DD')
then try to convert it into date for this format:
to_date((TO_CHAR(<date_column>,'YY/MM/DD')),'YY/MM/DD')
As to_date always converts to default date type of YYYY-MM-DD. What other way can I use to convert this into other format. I am using Informatica Powercenter, so I can not find other function other than TO_DATE.
I think we are ignoring basics - to_date() converts to a date format. Now it can be displayed in dd/mm/yyyy depending on setup in your DB client or if you are dumping in a file probably YYYY-MM-DD. And on a date filed you cfan use TO_CHAR o convert it to any format.
So, if your input is a string and is in 'YY/MM/DD' then use TO_CHAR(TO_DATE(imp_yymmdd,'YY/MM/DD'),'DD/MM/YYYY') - output will be a string of your desired format i.e. DD/MM/YYYY.
If your input is a date then use TO_CHAR(imp_date,'DD/MM/YYYY') - output will be a string of your desired format.
Date datatype has no format. You can format a string representing a date.
Assuming your input is date, just use TO_CHAR(yourdate, 'desiredformat').
If your input is a string, you first need to convert it to date then back to string again, with the desired format applied. So:
TO_CHAR(TO_DATE(yourstring, "format-it-comes-in"), "desired-format")
Which in your case would be:
TO_CHAR(TO_DATE(yourstring, "YYYY-MM-DD"), "YY/MM/DD")

Freemarker : Convert unix timestamp string to date format string

I am getting unix timestamp in String format in my ftl file. I want to reformat date to readable string such as "yyyy-MM-dd".
How should I convert timestamp to formatted date string ?
I got date in required format using below code:
calBookingEntry.getStartTime()?number?number_to_datetime?string["yyyy-MM-dd"]

ASP.Net VB string to date based on format used in string

I'm using a JavaScript datepicker that gives me the selected date based on the language. So when the language is Dutch I get an output like 21-09-2017 (dd-mm-yyyy) And for English 21/09/2017.
When I want to cast these Strings to Dates (CDate) I get a problem with the format. Day = Month or Month = Day. What is the best way to make a Date from a string based on the format used in the string?
A solution would be to write a function for each specific culture to handle the dates but i'm guessing there is a default function in .Net??
You can use DateTime.ParseExact to get what you want as shown here.
You can provide the format like so:
dateString = "15/06/2008 08:30" //Your Date time
format = "g" //General Fromat
provider = New CultureInfo("fr-FR") //French
result = Date.ParseExact(dateString, format, provider) //Parsed Result
this will result in: 6/15/2008 8:30:00 AM
This or course only works if you know the culture. Also you may want to check out the Date Time Format Strings found here.
Convert.ToDateTime(String).ToString("dd-MM-yyyy")
OR
DateTime.ParseExact(String, "dd/MM/yyyy", CultureInfo.InvariantCulture)

How to format the datetime in c#?

I got the current datetime by using the following code.
DateTime dt = DateTime.Now;
But it is in the format of, 2015-02-23 17:25:07.123
how to convert this to the format of, "02/23/2015"?
"But it is in the format of"
No it isn't. It's just a DateTime. If you want a particular text representation, call ToString on it, specifying the format. For example:
DateTime now = DateTime.Now;
string formatted = now.ToString("MM/dd/yyyy");
You might also want to specify the culture to use for formatting - that way you could just say "Use the right short date format" for example.
See the MSDN pages on custom date/time format strings and standard date/time format strings for more details.
Try this,
String.Format("{0:MM/dd/yyyy}", dt);

How can I convert datetime to date format in SQLite?

I want to show a date in DD-MM-YYYY format in a datagrid. By default, SQLite stores the data in date-time format. So how can I convert date-time format to date format in flex by using SQLite?
You can use strftime, from Date And Time Functions.
Example:
SELECT strftime('%d-%m-%Y', 'now')
output:
10-06-2010
Look up Java until Date. It has methods to convert and is supported in SQLite. However it is mostly deprecated and replaced with Calender.

Resources