I am having some trouble with find and replace. In my source workbook, I have text strings of project start dates. They read the first three letters of each day (Mon-Fri) then the associated date "Mon dd/mm/yyyy" for example. I need them in the form of dates "dd/mm/yyyy" so that I can use them after extraction in another workbook.
If I manually delete the "Mon " or use the replace all within the worksheet itself, I get the correct value of "dd/mm/yyyy" (converted to date format automatically). Serial number of the date 01/05/2015 for example being 42186.
However, when I use a macro to remove the "Mon " through the replace tool, the value of my dates changes to 05/01/2015. It is not a formatting error, but the actual value changing, new date serial number being 42009.
Any help as to why this is happening/how to stop it would be greatly appreciated!
I have included my macro replace code below.
Sub replace()
'Replace "Wed -Fri " with ""
Columns("C:C").Select
Selection.replace What:="Wed ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.replace What:="Fri ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.replace What:="Thu ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub
Using the Range.Replace function in VBA will automatically convert the date to the default format of mm/dd/yyyy unless you override it. You should first try setting the formatting for Column C to Custom-> dd/mm/yyyy.
Adding this line to your VBA Sub right below Columns("C:C").Select will effectively do the same thing: Selection.NumberFormat = "dd/mm/yyyy"
For this issue though, I would probably just avoid VBA altogether and use something like =RIGHT(A1,LEN(A1)-4) assuming cell A1 contains Mon 01/05/2015
This would grab all characters in the cell except for the first 4. This of course requires data integrity where all days have only three letters and all have a space between the day and the date.
This is happening because, the system Regional format is in mm/dd/yyyy format, what you have to do is, after replacing the text, you should format the date to "dd/mm/yyyy" format
Related
I'm looking for a way to set an arbitrary date, and every time I press a key it will print the day after it (tomorrow).
global jDate = "June 1, 1986"
^+z::
;Output our date in LongDate format
FormatTime, TimeString, %jDate%, LongDate
SendInput, %TimeString%
;Increment the date by a single day
jDate += 1, Days
Return
Unfortunately, it the code keeps starting jDate as today's current date/time rather than the past date I specify in the initial variable assignment. Not sure why. The incrementing works fine, it just increments starting from todays date rather that the 1986 date.
FormatTime is expecting any date/time input to be in the "YYYYMMDD..." format. Since what you've assigned to jDate doesn't fit that criterion, it assumes it's invalid and uses today's date. To make it work how you expect, just modify your jDate input.
jDate := "19860601" ; 1986 -> YYYY, 06 -> MM, 01 ->DD
A couple of things to note: (1) global is not needed in this context; (2) I would recommend getting out of the habit of assigning variables using the = comparator (use := assignment operator instead). It only works for legacy reasons but generates more confusion than it's worth. In the context that you're using it, the quotes would need to be removed.
I'm having trouble converting a couple of sting fields to date with Talend Open Studio. All date fields are coming to me via csv in the format "MM/dd/yyyy hh:mm:ss aa" For example "03/20/2018 2:40:03 PM"
Many date fields are fine, and conversion with the t-map component and the talend.date (parse date) is working as it should. The problem occurs in two fields where many almost all of the dates are coming in as "12/30/1899 00:00:00 AM"
I'm using the tmap to push the file to a toutputdelimited (CSV). The format of the fields with "12/30/1899 00:00:00 AM" is coming back as "#######################." Any ideas on how to handle the situation would be great. The output date format is "yyyy-MM-dd HH:mm:ss"
Again, all other fields are converting as they should. Its only the special case "12/30/1899 00:00:00 AM" that is causing problems.
Thans!
Since your dates can be of different formats, you need to read your column as a String type in your tFileInputDelimited, then inside a tMap, check the date type (a simple way to check it is by testing its length) and parse it using the correct date format:
tFileInputDelimited -- tMap -- output
In a tMap expression, you can have something like this :
row.created_ts.length() == 22 ? TalendDate.parseDate("yyyy-MM-dd hh:mm:ssX", row.yourdate) : TalendDate.parseDate("yyyy-MM-dd hh:mm:ss.SSSSSSX", row.yourdate)
I'm trying to insert date field in MS Word that will display tomorrow's date we one opens the document.
I can insert Today's date {DATE \# "dd/MM/yyyy"}, can we insert tomorrow's date using modified formula?
Thanks
Without VBA, the calculation is possible, but not straightforward, because the Word field language has very limited support for date-related operations.
Originally I thought Word would auto-update the DATE when you open or close/re-open the document, but further experiments suggest that even the second suggestion in here will not do that.
In the specific case described (add 1 day), you should be able to use the following field coding:
{QUOTE {SET xxx { DATE }}{SET yyy {xxx \#YYYY}}{SET mmm {xxx \#M}}{SET xxx1 {={xxx \#YYYYMMDD}+1 \#0000'-'00'-'00}}{=13-{xxx1 \#M} \#"'{xxx1}';'{=mmm-11 \#'{=yyy+1}-01-01';'{yyy}-{=mmm+1 \#00'-01'}'"}'"} \#DD/MM/YYYY}
All the {} must be the special field code brace pairs that you can insert on Windows Word using ctrl-F9, and (typically) on Mac Word using cmd-F9 or fn-cmd-F9, depending on your keyboard setup. You can change the format at the end ("\#DD/MM/YYYY" ) as required.
However, that set of field codes probably will not be updated automatically by Word when you open the document, so the user would need to select the field codes and press F9.
I originally thought Word would update the date on open and/or close/re-open using the following coding, but I now believe I was wrong. The one thing it does achieve on recent versions of Windows Word is to present the Date field in a "bubble" with an option to update the field:
{DATE \#"'{QUOTE {SET xxx { DATE }}{SET yyy {xxx \#YYYY}}{SET mmm {xxx \#M}}{SET xxx1 {={xxx \#YYYYMMDD}+1 \#0000'-'00'-'00}}{=13-{xxx1 \#M} \#"'{xxx1}';'{=mmm-11 \#'{=yyy+1}-01-01';'{yyy}-{=mmm+1 \#00'-01'}'"}'"} \#DD/MM/YYYY}'"}
Here is some pseudocode for the algorithm:
Set xxx to the date.
Set yyy to the 4-digit year
Set mmm to the month
Set xxx1 to the date but with the day number incremented by 1. e.g., for 2016-12-31, that would be a string, "2106-12-32"
This is the tricky bit:
Try to extract the month from that date using { xxx1 \#M }. If the date is valid, { xxx1 \#M } will return a valid month number, i.e. in the range 1 to 12. If the date is not valid, { xxx1 \#M } will return xxx1, e.g. "2106-12-32", which the { = } field will treat as a calculation, i.e. "year-(a maximum of 12+32=44)", so it is always going to return a number larger than 12.
If xxx1 is a valid date then
result=xxx1
Else 'xxx1 is not a valid date so...
If mmm (the original month) is 12 then
result = "(yyy+1)-01-01"
Else
result = "yyy-(mmm+1)-01"
End If
End If
Apply the date format you want to "result".
NB, this also relies on the assumption that Word always correctly recognises the month and day when you specify a date in the format "YYYY-MM-DD", regardless of the locale, in other words that "2016-04-01" is always recognised as 01 April 2016, never as 04 January 2016. If anyone can provide a counter-example, then the assumption is wrong, the field coding will need to change, and will probably need to be locale-dependent.
I have found a statement that compares two dates to see if one is greater than another:
If Format(Date, "m/d/yyyy") > #1/1/2000# Then MsgBox "Okay"
That's basically saying if today is later than January 1st, 2000 then pop up a message box.
This is fine if I am putting the date in the code (i.e., 1/1/2000), but I would like to get a date from the user during run-time and can't figure out how to incorporate that into the statement above.
If I provide a TextBox for the user to enter a date, I have surrounded the text with the # symbol:
If MyDate > "#" & Text1.Text & "#" then
That does not work. I've tried converting the text to Double, Integer, and Long. I have no idea how to use the enclosing # symbols with user input.
Thanks in advance for your help.
Use CDate(Text1.Text) to convert a string to a date. In reality you will want to do some checking to make sure that the value entered is a valid date, something along the lines of:
Dim myDate As Date
If IsDate(Text1.Text) Then
MyDate = CDate(Text1.Text)
Else
'Indicate the error to the user
End If
The # characters are "date quotes", if you will - they serve the same purpose for date literals as " does to delimit a string literal. You can't just concatenate # to a value to make it into a date.
Disclaimer: you might need to install
a font/typeface which supports
Japanese if you see messed up
characters.
I'm trying to replicate what I've been doing so far with setlocale and strftime:
setlocale(LC_ALL, 'ja_JP.utf8');
$time = mktime();
echo strftime('%x', $time), '<br>';
Output:
2010年01月06日
Using Zend_Date - but I haven't been able to reproduce the same formatting with the japanese symbols for year, month and day.
Attempt #1:
$locale = new Zend_Locale('ja_JP');
$date = new Zend_Date( strtotime('yesterday'), null, $locale);
//echo $date->toString('YYYY abcdefghijklmnopqrstuvwxy M dE');
echo $date->get('YYYY MMM DD');
Output:
2010 1月 004
Attempt #2:
echo $date->get(Zend_Date::DATE_FULL);
Output:
2010年1月5日火曜日
My first attempt I can't seem to find a working constant to produce the YEAR and day symbols. The latter uses a standardized format but I need to customize it so there's a 0 preceding the month, and I want to be more in control.
In the future I may want to make it flexible so for example, en_US dates won't have those letters coming after the year/month/day but it would only apply to languages such as Japanese and others, where it's more common, or if I misunderstood and it isn't really common then please inform me.
Thanks in advance.
Seems what I needed was the DATE_LONG constant, which internally points to 'FFFF' - I'm trying to learn the inner workings of how the Date class corresponds with the Locale class to generate the whole string including the symbols now.
Update: I kept trying to find where it actually used date units instead of date formats, found the right data I need:
<dateFormatLength type="long">
<dateFormat>
<pattern>y年M月d日</pattern>
</dateFormat>
</dateFormatLength>
So it parses this and replaces the y, M, d, returns the formatted date.