cast string to date time in classic asp - datetime

I have a string of "DD/MM/YYYY HH:MM:SS" which I need to transform to a date, the problem is the default conversion goes "MM/DD/YYYY HH:MM:SS" unless the day is >12 in which case it switches. I'd like to ensure that my day's go into the day portion of the date/time.
Is there an easy fix to this?

' Parse a date in ISO 8601 "universal combined" format: YYYY-MM-DDTHH:MM:SSZ
' This function ALSO accepts SQL date format: YYYY-MM-DD HH:MM:SS
Function CDateFromUniversal( s )
CDateFromUniversal = CDate(Mid(s, 1, 10) & " " & Mid(s, 12, 8))
End Function

use the format function
this could do it too

Related

How to save Date type data as string with format "dd-MM-yyyy" in SQLite?

The Sqlite normal date string format is yyyy-MM-dd. How can I save it as dd/MM/yyyy? Should I keep the yyyy-MM-dd format when working with the database and use dd/MM/yyyy only with the end user interface?
Edit 1:
I want to save my date datas as 'dd/MM/yyyy' in SQLite to be the same as my locale date format. But the date comparison is return wrong result with this format. I changed the date string in DB to 'yyyy-MM-dd' and the date comparison work perfect. Is 'yyyy-MM-dd' is the only string format which SQLite can understand as date?
You can use the strftime() function which accepts as its first parameter a format string:
SELECT strftime('%d/%m/%Y', 'now');
Output:
06/10/2015
The strftime() function gives the ability to convert Y-m-d into d/m/Y or any other format you want. So you can continue to store your date data as is in the database, and you can query it out however you wish.
you can use date formatter code:
NSString *myString = #"2012-11-22 10:19:04";
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = #"yyyy-MM-dd HH:mm:ss";
NSDate *yourDate = [dateFormatter dateFromString:myString];
dateFormatter.dateFormat = #"dd-MMM-yyyy";
NSLog(#"%#",[dateFormatter stringFromDate:yourDate]);

How do you display the current date and time in Crystal Reports?

How do you display the current date and time in Crystal Reports?
Create a new formula and use:
CurrentDateTime
This would display the following:
18.05.2015 2:28:46PM
Then you can format it using ToText:
ToText(CurrentDateTime, "dd/MM/yyyy HH:mm:ss")
Which would display (same as first example's datetime) :
18/05/2015 14:28:46
Just to add:
ToText(currentdatetime,"dd/M/yy hh:mm") will display as 8/2/17 04:26
where as
ToText(currentdatetime,"d/M/yy HH:mm") will display as 8/2/17 16:26
(For those who would like to change the time to a 24 hour format)
CurrentDateTime will return dd.MM.yyyy hh:mm:ss
if you want to display the date without any Delimiter and not in datetime, then TONUMBER(ToText(CurrentDateTime,"yyMMdd")) will return yyMMdd
[datetime][crystalreport]

Format date from the following string in asp.net

I'm new to coding in asp.net and I'm struggling to format the date I've managed to pull from our CRM content pages' live date. I've wrote the following code that manages to pull and display the date the page was created:
TheDate = DR["LiveDate"].ToString();
But it formats the date and time like this:
13/11/2012 00:00:00
How can I modify my above code to just display the date like so:
Tuesday, 13 November 2012
Or, just without the time
13/11/2012
Thanks,
I assume that DR is a DataRow, isn't it?
If DR["LiveDate"] is already a DateTime column don't convert it to a localized string via ToString. Just cast it accordingly, for example via Field extension method:
DateTime dt = DR.Field<DateTime>("LiveDate");
If it's not a DateTime but a string you have to parse it to DateTime:
DateTime dt = DateTime.Parse(DR.Field<String>("LiveDate"));
If you want Tuesday, 13 November 2012 as result use:
string result = dt.ToString("dddd, dd MMMM yyyy", CultureInfo.InvariantCulture);
If you want 13/11/2012 use:
string result = dt.ToShortDateString();
or
string result = dt.ToString("d");
if your culture uses / as separator
otherwise
string result = dt.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);
Further informations: http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
for your second question, try
TheDate = DR["LiveDate"].ToString("dd/MM/yyyy")

How can I remove the Time from a DateTime value?

In my SQL database, I have a column formatted as DateTime and when I retrieve data from that column in ASP.NET, I catch it on the Date variable, than pass the value to textbox:
Dim Y As Date = dt.Rows(0)("SCH_DATE")
txtSchedDate.Text = Y.Date.ToString
but when I debug my website, the txtSchedDate.Text still gives me the full DateTime value:
7/17/2013 12:00:00 AM
is it possible to eliminate the time value here and just return the date?
Have you tried using something like
txtSchedDate.Text = Y.Date.ToString("MM/dd/yyyy")
or which ever format you wish to display.
Have a look at
DateTime.ToString Method (String)
Converts the value of the current DateTime object to its equivalent
string representation using the specified format.
Custom Date and Time Format Strings
Standard Date and Time Format Strings
Convert.ToDateTime(dt.Rows(0)("SCH_DATE")).ToString("M/d/yyy")
you can get date by txtSchedDate.Text = Y.Date.ToShortDateString()
Besides answers above, you can try converting it in SQL server
SELECT CONVERT(varchar(15), GETDATE(), 11)
Keep in mind after converting it's VARCHAR(15) instead of DATETIME.
Once you have a Date object, you can get the constituent pieces if you wish as well, like this:
Dim Y As Date = dt.Rows(0)("SCH_DATE")
txtSchedDate.Text = Y.Date.Year & "-" & Y.Date.Month & "-" & Y.Date.Day
Or you can use the custom and standard date and time format strings mentioned by others.

VB.NET convert date string ddMMyyhhmmss to Date Object

I have a string that holds a value in the format of ddMMyyhhmmss.
Example 240512024707
I need to be able to convert this date to a real .NET Date object.
I am currently using CDate but it seems CDate does not recognize the format, is there any way of specifying the string format to CDate ???
row.Item("NoteDate") = CDate(n.noteText.Substring(0, 12).ToString).ToString("dd/MM/yyyy hh:mm:ss")
You have the string with the date, you know the exact format string - use DateTime.ParseExact (or DateTime.TryParseExact if you wish to avoid the potential exception being thrown):
DateTime.ParseExact("240512024707", "ddMMyyhhmmss", CultureInfo.InvariantCulture)

Resources