Formatting Dates with "-" separators and not "/" - excel

A file is given to me in such a way that the date is included in the file name.
I have written a code to retrieve the file based on the date.
The file name, which cannot be changed, is xxxx_MM-DD-YYYY.
For half of the month my code works. e.g of the file name is xxxx_05-15-2020, the user can enter in the date, 05-15-2020, and it will be retrieved.
If the user puts in 05-03-2020 , Excel changes this format to 05/03/2020, and based on the new format, the code will not work as it is looking for "-" separators and not "/".
How can I choose MM-DD-YYYY formatting?

The following should work regardless whether your date is stored as a date type variable or string type variable:
dateString = Replace(dateVar, "/", "-")
If you need to convert the date to a date type variable, you could use cDate like this
cDate(dateString)
Assuming your date is stored as a date type variable, you could format it this way:
Format(dateVar, "dd-mm-yyyy")
Read more about the Format function here

Related

Date export from Matlab to excel

i have a set of data for couple of days and the names of the data files like this
name='Newyork20200915'
which is for the 15th of September and i want to export only the date to excel like shown below
So how can i get the date from the name string ?
Thanks in advance
Assuming that the other part of name will not contain any digits besides the date, you can use regexp to get all the digits from the character array:
name = 'Newyork20200915'
date_only = regexp(name, '\d*', 'match')
Next, you can convert this date string to a serial date number using datenum, by providing the format in which the date is currently. And then use datestr to format it to your desired format.
date_formatted = datestr(datenum(date_only, 'yyyymmdd'), 'dd. mmm')
date_formatted =
'15. Sep'

Finding multiple dates from a string in Python without using parsing packages

Trying to find dates in a string, but code doesnt work when I use "/" as a date separator. Also if i enter multiple dates. it returns only one.
I'd like to use all valid date separators viz "/" "-" "." and get all the dates in the string.
Also i'd like to use all the date formats like ddmmyy mmddyy yymmdd yyyymmdd ddmmyyyy mmddyyyy.
str = " here is some text in 31-01-2019 my string 01/02/2019 for fun 02.02.2019"
match = re.search('\d{2}-\d{2}-\d{4}', str)
date = dt.strptime(match.group(), '%d-%m-%Y').date()
print(date)
re.findall(r'\b\d{2}[-\./]\d{2}[-\./]\d{2}\b|\b\d{4}[-\./]\d{2}[-\./]\d{2}\b|\b\d{2}[-\./]\d{2}[-\./]\d{4}\b',lsstr)
output : ['31-01-2019', '01/02/2019', '02.02.2019']
Use this regexp to find all the dates present in the string.

Changing format of TODAY() in excel

I'm using today to aquire todays date and then adding a static value to the end of it using the following:
=TODAY()&"T23:00:00"
Which Returns 43202T23:00:00
I really need it in the format 2018-04-12T23:00:00
Any help on this would be great!
There are a couple ways to accomplish this, depending on whether your goal is a formatted String (to display) or a numeric value (such as data type Date) for storing or using with calculations.
If you want a formatted date/time result (to display to the user)...
Use the TEXT worksheet function:
=TEXT(TODAY(),"yyyy-mm-dd")&"T23:00:00"
...the reason this works is because TODAY() returns a Date data type, which is basically just a number representing the date/time, (where 1 = midnight on January 1, 1900, 2 = midnight on January 2, 1900, 2.5 = noon on January 2, 1900,etc).
You can convert the date type to a String (text) with the TEXT function, in whatever format you like. The example above will display today's date as 2018-04-12.
If, for example, you wanted the date portion of the string displayed asApril 12, 2018 then you would instead use:
TEXT(TODAY(),"mmmm d, yyyy")
Note that the TEXT worksheet function (and VBA's Format function) always return Strings, ready to be concatenated with the rest of the String that you're trying to add ("T23:00:00").
If you want to use the result in calculations...
If you instead want the result to be in a Date type, then instead of concatenating a string (produced by the TEXT function) to a string (from "T23:00:00"), you could instead add a date to a date:
=TODAY()+TIME(23,0,0)
or
=TODAY()+TIMEVALUE("23:00")
..and then you can format it as you like to show or hide Y/M/D/H/M/S as necessary with Number Formats (shortcut: Ctrl+1).
More Information:
MSDN : TEXT Function (Excel)
MSDN : TIMEVALUE Function (Excel)
MSDN : TIME Function (Excel)

Formatting magento timestamp to readable excel format

I download invoice reports from my magento website. They hold a date format I am not able to change to a standard date format. This is what it looks like: 1 aug. 2016 15:24:08
What formula can I use to have excel change it to a format like 13-08-16 (Dutch Format) ( I don't need the time for the moment).
Assuming that your 3 letter month names end with a dot in magneto data, you can use this where original data is in cell A1
=TEXT(SUBSTITUTE(LEFT(A1,FIND(".",A1)+5),".",""),"dd-mm-yy")
Check if "1 aug. 2016 15:24:08" is:
a\ pure string (String Type data; "wroted" date)
or
b\ string representation of Date type data (formatted date)
.

Stata: how to change a string variable to a date?

I'm new to Stata, and I'm wondering how can I change a string variable which contains a date to a date format.
The data in the variable looks like this:
yyyy-mm-dd
Should I first remove the dashes so that Stata can recognize the format in order to later use gen var = date() ?
Thank you for your help.
The Stata date function is smart about removing separator characters. See help datetime_translation under the section "the date function"
If your dates are in v1 and in the form yyyy-mm-dd you can specify the commands:
generate v2 = date(v1, "YMD")
format %td v2
The YMD is called a mask, and it tells Stata the order in which the parts of the date are specified. The second line will assign the variable the Stata daily date format, which means that when you look at that variable in the data, it will be shown in human readable form. The date is stored, however, as the number of days since January 1, 1960.
The best way to experiment with the date function is to use the display command. The first line will display an integer representing the number of days since January 1, 1960. The second line will display the date in a human readable format.
display date("2013-08-14", "YMD")
display %td date("2013-08-14", "YMD")
you can look here to see how to convert to data in Stata or do like this
tostring datedx, replace
generate str4 dxyr1= substr(datedx,1,4)
generate str2 dxmo1 = substr(datedx,6,7)
generate str2 dxda1 = substr(datedx,9,10)
destring dx*, replace
gen datedx1 = mdy(dxmo1, dxda1, dxyr1)

Resources