DateTime Parse from FTP - asp.net

I am using FTP and I have retrieved a list of Files. In the files command line there is a datetime field.
It reads
11-13-13 11:31AM
Can anyone tell me how I can parse this. I thought this might work.
DateTime.ParseExact(date,"MM-DD-YY HH:MMtt", System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat); But i still get an exception.

day should be dd not DD
Year should be yy not YY
since hour is 12 hour format it should be hh also MM (minutes should be mm)
DateTime.ParseExact(date,"MM-dd-yy hh:mmtt",...)
eg:-
DateTime date = DateTime.ParseExact("11-13-13 11:31AM", "MM-dd-yy hh:mmtt", System.Globalization.CultureInfo.InvariantCulture);
Response.Write(date);

Related

How do I show time in ASP.NET?

I have a label in my asp.net web site that will shows the time. I want the output like here. in the morning like this: 08:26 and after 12 am,it shows 15:28
My code does not work. It only supports the first part.
DateTime tim = DateTime.Now;
int hh = p.GetHour(tim);
int mm = p.GetMinute(tim);
Label7.Text = DateTime.Now.ToString("hh:mm");
According to the Custom date and time format strings docs page - you can see:
"hh" The hour, using a 12-hour clock from 01 to 12.
"HH" The hour, using a 24-hour clock from 00 to 23.
So in your case - just use the capitalized HH for your formatting:
Label7.Text = DateTime.Now.ToString("HH:mm");
and you should get what you're looking for.

How to get month format with 0 after evaluate using Robot framework

I try to get month and year format like "06/19" after evaluated month but I got just "6/19".
Month and year
${currentYear}= Get Current Date result_format=%y
${currentDate}= Get Current Date
${datetime} = Convert Date ${currentDate} datetime
${getMonth}= evaluate ${datetime.month} - 1
log to console ${getMonth}/${currentYear}
I already tried another way by created variable #{MONTHSNO} ${EMPTY} 01 02 03 04 05 06 07 08 09 10 11 12 and return ${MONTHSNO}[${getMonth}]/${currentYear} I got 06/19 but I'm not sure the robot have another way to convert month to "06" by without to make the variable like these.
You can acheive this by using a custom keywords that will return the date in month/year format
Then you can use relativedelta() to subtract a month from your date
to install dateutil:
pip install python-dateutil
test.py
from datetime import datetime
from dateutil.relativedelta import relativedelta
def return_current_date_minus_one_month():
strDate = datetime.today()
Subtracted_date = strDate + relativedelta(months=-1)
Date = Subtracted_date.strftime('%m/%y')
return Date
test.robot
*** Settings ***
Library test.py
*** Test Cases ***
Month and year
${current_date} = Test.Return Current Date Minus One Month
log ${current_date}
result = ${current_date} = 06/19
When you run Evaluate command, you are running python commands. So let's take a look at datetime docs:
https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior
They have this part in the end saying that library time can be useful. So I suggest you to use this command to return month in 0X format:
${getMonth}= evaluate time.strftime("%m")
This just return 07 to me (because now it's July)
You can substract from your current date one month like this with the DateTime Library:
${date1}= Get Current Date result_format=%d.%m.%Y
${date2}= Substract Time To Date ${date1} 30 days date_format=%d.%m.%Y result_format=%m.%Y
maybe this helps

how do you use the IF COMMAND to convert a date from 5/1/2017 to 05012017 in microsoft access?

how do you use the IF COMMAND to convert a date from 5/1/2017 to 05012017 in microsoft access?
You don't. Format is for this if month is May:
TextDate = Format(YourDateValue, "mmddyyyy")
or, if month is January:
TextDate = Format(YourDateValue, "ddmmyyyy")

correct sum of hours in access

I have two columns in an access 2010 database with some calculated field:
time_from time_until calculated_field(time_until-time_from)
10:45 15:00 4:15
13:15 16:00 2:45
11:10 16:00 4:50
08:00 15:00 7:00
08:00 23:00 15:00
Now so far, it is good: calculated field did its job to tell me total hours and mins...
now, I need a sum of a calculated field....
I put in an expression builder: =Sum([time_until]-[time_from])
I guess total sum should give me 33:50... but it gives me some 9:50. why is this happening? Is there a way to fix this?
update:
when I put like this:
=Format(Sum([vrijeme_do]-[vrijeme_od])*24)
I get a decimal point number... which I suppose is correct....
for example, 25hrs and 30mins is shown as 25,5
but, how do I format this 25,5 to look like 25:30?
As #Arvo mentioned in his comment, this is a formatting problem. Your expected result for the sum of calculated_field is 33:50. However that sum is a Date/Time value, and since the number of hours is greater than 24, the day portion of the Date/Time is advanced by 1 and the remainder 9:50 is displayed as the time. Apparently your total is formatted to display only the time portion; the day portion is not displayed.
But the actual Date/Time value for the sum of calculated_field is #12/31/1899 09:50#. You can use a custom function to display that value in your desired format:
? duration_hhnn(#12/31/1899 09:50#)
33:50
This is the function:
Public Function duration_hhnn(ByVal pInput As Date) As String
Dim lngDays As Long
Dim lngMinutes As Long
Dim lngHours As Long
Dim strReturn As String
lngDays = Int(pInput)
lngHours = Hour(pInput)
lngMinutes = Minute(pInput)
lngHours = lngHours + (lngDays * 24)
strReturn = lngHours & ":" & Format(lngMinutes, "00")
duration_hhnn = strReturn
End Function
Note the function returns a string value so you can't do further date arithmetic on it directly.
Similar to the answer from #HansUp, it can be done without VBA code like so
Format(24 * Int(SUM(elapsed_time)) + Hour(SUM(elapsed_time)), "0") & ":" & Format(SUM(elapsed_time), "Nn")
I guess you are trying to show the total in a text box? the correct expression would be =SUM([calculated_field_name]).

Groovy: How do you initialise and compare date/time values from different timezones?

I need to standardise and compare date/time fields that are in differnt timezones. eg How do you find the time difference between the following two times?...
"18-05-2012 09:29:41 +0800"
"18-05-2012 09:29:21 +0900"
What's the best way to initialise standard varaibles with the date/time?
The output needs to display the difference and normalised data in a timezone (eg +0100) that is different to the incoming values and different to the local environment.
Expected Output:
18-05-2012 02:29:41 +0100
18-05-2012 01:29:21 +0100
Difference: 01:00:20
import java.text.SimpleDateFormat
def dates = ["18-05-2012 09:29:41 +0800",
"18-05-2012 09:29:21 +0900"].collect{
new SimpleDateFormat("dd-MM-yyyy HH:mm:ss Z").parse(it)
}
def dayDiffFormatter = new SimpleDateFormat("HH:mm:ss")
dayDiffFormatter.setTimeZone(TimeZone.getTimeZone("UTC"))
println dates[0]
println dates[1]
println "Difference "+dayDiffFormatter.format(new Date(dates[0].time-dates[1].time))
wow. doesn't look readable, does it?
Or, use the JodaTime package
#Grab( 'joda-time:joda-time:2.1' )
import org.joda.time.*
import org.joda.time.format.*
String a = "18-05-2012 09:29:41 +0800"
String b = "18-05-2012 09:29:21 +0900"
DateTimeFormatter dtf = DateTimeFormat.forPattern( "dd-MM-yyyy HH:mm:ss Z" );
def start = dtf.parseDateTime( a )
def end = dtf.parseDateTime( b )
assert 1 == Hours.hoursBetween( end, start ).hours
Solution:
Groovy/Java Date objects are stored as the number of milliseconds after
1970 and so do not contain any timezone information directly
Use Date.parse method to initialise the new date to the specified format
Use SimpleDateFormat class to specify the required output format
Use SimpleDateFormat.setTimeZone to specifiy the timezone of the output
data
By using European/London timezone rather than GMT it will
automatically adjusts for day light savings time
See here for a full list of the options for date time patterns
-
import java.text.SimpleDateFormat
import java.text.DateFormat
//Initialise the dates by parsing to the specified format
Date timeDate1 = new Date().parse("dd-MM-yyyy HH:mm:ss Z","18-05-2012 09:29:41 +0800")
Date timeDate2 = new Date().parse("dd-MM-yyyy HH:mm:ss Z","18-05-2012 09:29:21 +0900")
DateFormat yearTimeformatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss Z")
DateFormat dayDifferenceFormatter= new SimpleDateFormat("HH:mm:ss") //All times differences will be less than a day
// The output should contain the format in UK time (including day light savings if necessary)
yearTimeformatter.setTimeZone(TimeZone.getTimeZone("Europe/London"))
// Set to UTC. This is to store only the difference so we don't want the formatter making further adjustments
dayDifferenceFormatter.setTimeZone(TimeZone.getTimeZone("UTC"))
// Calculate difference by first converting to the number of milliseconds
msDiff = timeDate1.getTime() - timeDate2.getTime()
Date differenceDate = new Date(msDiff)
println yearTimeformatter.format(timeDate1)
println yearTimeformatter.format(timeDate2)
println "Difference " + dayDifferenceFormatter.format(differenceDate)

Resources